by Al Beecy
January 9, 2009
In order to get a reference to a DropDownList (or any other control that needs to be populated or configured) during an edit using a RadGrid edit template, you need to do three things:
1. Declare an event handler for the ItemDataBound event in the ReadGrid tag.
OnItemDataBound="RadGrid1_ItemDataBound"
2. Add the control to your template.
<asp:DropDownList ID="ddl" runat="server"> </asp:DropDownList>
3. Add the event handler to the code-behind.
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
if ((e.Item is GridEditFormItem) && (e.Item.IsInEditMode))
{
GridEditFormItem editform = (GridEditFormItem)e.Item;
DropDownList ddl = (DropDownList)editform.FindControl("ddl");
ddl.Items.Add("foo");
ddl.Items.Add("bar");
}
}
Applies to: RadGrid for ASP.NET AJAX Version Q3 2008