I am using the following code to set a datasource for a dropdown inside of my gridview but it is not working.
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
DropDownList drop = (DropDownList)e.Row.FindControl("folderslist");
drop.DataSource = list;
drop.DataBind();
}
list is a list of strings, which binds find to a dropdown I have outside of my gridview. However the code above does not populate the dropsdown inside the 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>
The dropdown in gridview is
foldersnotfolderlist. Give folders in e.Row.FindControl() method. Debugging the code could help you whats happening. Also make sure you have data in list.