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 131 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Simon
Top achievements
Rank 2
Simon asked on 29 Oct 2008, 11:37 PM
Hi

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

Cheers

Simon

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

<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">
  <Columns>
   <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" />
  </Columns>
  <EditFormSettings UserControlName="/UserControls/ProductEditor.ascx" EditFormType="WebUserControl">
   <EditColumn UniqueName="EditCommandColumn1"></EditColumn>
  </EditFormSettings>
 </MasterTableView>
</telerik:RadGrid>






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
{
 get
 {
  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)
     };
  productList.Add(prod1);
  productList.Add(prod2);
  Session["Products"] = productList;
  return productList;
 }
}


1 Answer, 1 is accepted

Sort by
0
Vlad
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,
Vlad
the Telerik team

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