I have been trying to add a dropdown control in a column of a telerik grid view. Below is the code snippet. when I use the Find Control on dropdown, it returns null and the data is not bound.
ASP
<telerik:GridTemplateColumn AllowFiltering="False" ShowFilterIcon="False">
<HeaderStyle HorizontalAlign="Center" />
<HeaderTemplate>
Change Sort Order
</HeaderTemplate>
<ItemStyle HorizontalAlign="Center" Width="5%"/>
<ItemTemplate>
<asp:DropDownList ID="myDropDown" DataTextField="TextFieldValue" DataValueField="ValueFieldValue" runat="server"/>
</ItemTemplate>
</telerik:GridTemplateColumn>
C# Code
protected void gdvFMclevel1_ItemDataBound(object sender, GridItemEventArgs e)
{
GridItem item = (GridItem)e.Item;
DropDownList list=(DropDownList)item.FindControl("myDropDown");
Controller c = new Controller();
DataSet ds = new DataSet();
ds = c.GetSortList();
if (ds.Tables[0].Rows.Count > 0)
{
list.DataSource = ds.Tables[0];
list.DataTextField = "Order";
list.DataValueField = "SortOrder";
list.DataBind();
}
}
Please let me know how can I get the data populated in the dropdown. I am getting an object reference exception on this.