我正在使用下面的代碼來爲我的gridview中的下拉菜單設置一個數據源,但它不工作。設置gridview下拉列表的datasource
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
DropDownList drop = (DropDownList)e.Row.FindControl("folderslist");
drop.DataSource = list;
drop.DataBind();
}
列表是一個字符串列表,結合找到一個下拉我有我的GridView之外。但是,上面的代碼不會填充gridview中的下拉菜單。
<asp:GridView ID="GridView1" HorizontalAlign="Center"
AutoGenerateColumns="false" CellSpacing="5" CellPadding="5" CssClass="GridView" Font-Size="Small"
runat="server" OnRowDataBound = "GridView1_RowDataBound" >
<Columns>
<asp:BoundField HeaderText="From" DataField="From" />
<asp:BoundField HeaderText="Subject" DataField="Subject" />
<asp:BoundField HeaderText="Received" DataField="Received" />
<asp:TemplateField HeaderText="Attachments" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:ImageButton runat="server" ID="attach" CommandName="viewattachments" Text="More"
ImageUrl="~/images/notes.png" visible='<%# System.Convert.ToBoolean((DataBinder.Eval(Container.DataItem, "Attachments").ToString() == "") ? false : true) %>' />
</ItemTemplate>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:TemplateField>
<asp:TemplateField HeaderText="Move To" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:DropDownList ID="folderslist" runat="server"></asp:DropDownList>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:TemplateField>
</Columns>
</asp:GridView>
你能告訴我們HTML一側GridView和下拉列表是什麼? – Adil