我正在使用以下代码为我的 gridview 中的下拉菜单设置数据源,但它不起作用。
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
DropDownList drop = (DropDownList)e.Row.FindControl("folderslist");
drop.DataSource = list;
drop.DataBind();
}
list 是一个字符串列表,它将 find 绑定到我在 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>