I am using a Telerik RadGrid and using an EditItemTemplate as shown in my ASP code below.
<telerik:GridTemplateColumn UniqueName="TemplateColumn" HeaderText="Role">
<ItemTemplate>
<asp:Label ID="lblRole" runat="server"
Text='<%# DataBinder.Eval(Container.DataItem, "Role") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="ddl1" runat="server" UniqueName="Roles"/>
</EditItemTemplate>
</telerik:GridTemplateColumn
I am attempting to populate the dropdown using Entity Framework with this C# code:
protected void gvMembers_ItemDataBound(object sender, GridItemEventArgs e)
{
var roles = (from c in DbContext.roles
select new { c.Role1, c.RoleID }).ToList();
GridEditableItem item = e.Item as GridEditableItem;
//// access/modify the edit item template settings here
DropDownList list = item.FindControl("Roles") as DropDownList;
list.DataTextField = "Role1";
list.DataValueField = "RoleID";
list.DataBind();
}
I am getting an "Object reference not set to an instance of an object." Since I am relatively new to programming I am stumped by this error message it appears to me I am not able to find that Roles control. I have attempted to use the Control ID put get the same results. I have spent a lot of time trying to solve this problem so any help with this would be great.