This is a migrated thread and some comments may be shown as answers.

RadGrid with User Control Edit Issue, unable to find UserControl

1 Answer 133 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 2
Simon asked on 29 Oct 2008, 11:37 PM

I am using a RadGrid, and trying to use a custom User Control edit form. I have just created a test page, where I am binding the RadGrid to a List<T> of a custom Business Object.

When I click on the EditCommandColumn, I notice that the e.Item.IsInEditMode is always false, and I am unable to retrieve a reference to the UserControl using the documented method of:

GridEditableItem editedItem = e.Item as GridEditableItem;
UserControl userControl = (UserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID);

userControl is always null :(

I am using a <telerik:AjaxScriptManager> to perform all operations using AJAX if this helps shed any light on the matter



ASPX Page is as follows:
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
  <telerik:AjaxSetting AjaxControlID="RadGrid1">
    <telerik:AjaxUpdatedControl ControlID="RadGrid1" />

<telerik:RadGrid ID="RadGrid1" runat="server" Skin="WebBlue" GridLines="None" AllowPaging="True" AllowSorting="True" Width="97%" AutoGenerateColumns="False" ShowStatusBar="true" OnNeedDataSource="RadGrid1_NeedDataSource" OnItemCommand="RadGrid1_ItemCommand" OnItemDataBound="RadGrid1_ItemDataBound">

 <MasterTableView GridLines="None" Width="100%" CommandItemDisplay="Top" DataKeyNames="Id">
   <telerik:GridBoundColumn DataField="ProductCode" HeaderText="Prod Code" />
   <telerik:GridBoundColumn DataField="Description" HeaderText="Desc" />
   <telerik:GridBoundColumn DataField="Quantity" HeaderText="Qty" />
   <telerik:GridBoundColumn DataField="DeliveryDate" HeaderText="Del Date" DataFormatString="{0:dd/MM/yy}" />
   <telerik:GridEditCommandColumn UniqueName="EditCommandColumn" />
  <EditFormSettings UserControlName="/UserControls/ProductEditor.ascx" EditFormType="WebUserControl">
   <EditColumn UniqueName="EditCommandColumn1"></EditColumn>

CS File is as follows:

protected void RadGrid1_EditCommand(object source, GridCommandEventArgs e)
    GridEditableItem editedItem = e.Item as GridEditableItem;
    UserControl userControl = (UserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID);
    if ( userControl == null)
        throw new Exception("Unable to find UserControl");
private List<Objects.Product> ProductList
  Object oProductList = Session["Products"];
  if (oProductList != null)
   return oProductList as List<Objects.Product>;
  List<Objects.Product> productList = new List<Product>();
  Product prod1 = new Product
     Id = 1,
     Description = "Product One (Event)",
     ProductCode = "1001",
     ProductType = Enums.ProductType.Event,
     DeliveryDate = DateTime.Now.AddMonths(1)
  Product prod2 = new Product
     Id = 2,
     Description = "Product Two (Material)",
     ProductCode = "1002",
     ProductType = Enums.ProductType.Material,
     DeliveryDate = DateTime.Now.AddMonths(2)
  Session["Products"] = productList;
  return productList;

1 Answer, 1 is accepted

Sort by
Telerik team
answered on 30 Oct 2008, 07:28 AM
Hi Simon,

EditCommand is to early to find the user control. This command will tell the grid to open the edit form and you can find the user control in the next lifecycle using ItemCreated. You can check our online examples for more info.

All the best,
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Asked by
Top achievements
Rank 2
Answers by
Telerik team
Share this question