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

Accessing items in child grid

3 Answers 461 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bill
Top achievements
Rank 1
Bill asked on 25 Jan 2011, 12:24 AM
I am trying to edit a checkbox in a grid on a popup edit form and can not seem to get acces to the control I need. The basic layout is I have a page with a RadGrid. The grid has a popup edit form that has a few controls (labels and textboxes) and a new grid that is populated when you edit the parent grid. On editing the parent I get primay key from the ItemDatabound if the item is in edit mode and is a grid editform item. I then
run my query to populate the child grid with the selected details I desire.
I am trying to allow a user to check or uncheck a checkbox that I then use to update a value in the database. I can access the underlying object in the itemcommand on the update by getting a reference to the grid and they getting the EditItems to then iterate through each GridItem. I have AllowMultiEdit set on my child grid and on the child grid pre_render I set each row to edit mode.What I don't have though is the checkbox control. If I try and do a find control on the child grid in the Editform I get a null back.

Here is a snippet of how I am defining the checkbox on the child grid:
<EditFormSettings EditFormType="Template">
  <PopUpSettings Width="800" Height="500" />
       <FormTemplate>
          ...
         <telerik:GridTemplateColumn UniqueName="chkResubmitted">
            <HeaderTemplate>
                 <asp:CheckBox id="headerChkbox" OnCheckedChanged="ToggleSelectedState" AutoPostBack="True"
                     runat="server" Text=" resubmitted" ></asp:CheckBox>
              </HeaderTemplate>
              <EditItemTemplate>
              <asp:CheckBox id="chkResubmittedEdit" runat="server" />
              </EditItemTemplate>
              <ItemTemplate>
              <asp:CheckBox id="chkResubmittedItem" OnCheckedChanged="ToggleRowSelection"  
                AutoPostBack="True" runat="server"></asp:CheckBox>
               </ItemTemplate>
               </telerik:GridTemplateColumn>

In my UpdateCommand I tried accessing the checkbox with this:
if (e.CommandName == RadGrid.UpdateCommandName)
          {
              GridEditableItem editedItem = e.Item as GridEditableItem;
              RadGrid dtlgrid = (editedItem.FindControl("grdClaimDetail") as RadGrid);
                
              CheckBox chk = dtlgrid.FindControl("chkResubmittedEdit");
              ...
 
Any suggestions on how I can access the checkbox on my child grid in my edit popup?

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 25 Jan 2011, 10:57 AM
Hello Bill,

If you want to access the CheckBox in EditItemTemplate of child grid, you need to access the edit row first and then get the control like below.

C#:
GridEditFormItem editedItem = e.Item as GridEditFormItem;
RadGrid dtlgrid = (editedItem.FindControl("grdClaimDetail") as RadGrid);
foreach(GridEditFormItem childeditItem in  RadGrid1.MasterTableView.GetItems(GridItemType.EditFormItem))
    // loops through each editItem in child grid
{
   CheckBox chk = childeditItem.FindControl("chkResubmittedEdit"); //accessing CheckBox
}

Thanks,
Princy.
0
Bill
Top achievements
Rank 1
answered on 25 Jan 2011, 04:10 PM
Thanks for the reply. I tried this:
GridEditFormItem editedItem = e.Item as GridEditFormItem; 
  RadGrid dtlgrid = (editedItem.FindControl("grdClaimDetail") as RadGrid);
  GridItem[] items = dtlgrid.MasterTableView.GetItems(GridItemType.EditFormItem);
  int count = items.Length;
  if (count > 0)
  {
      GridEditFormItem clm = items[0] as GridEditFormItem;
  }
  foreach (GridEditFormItem childeditItem in items)
  // loops through each editItem in child grid
  {
      CheckBox chk = childeditItem.FindControl("chkResubmittedEdit") as CheckBox; //accessing CheckBox
  }
And no editformitems are returned. My count was zero. I thought about making the GridTemplateColumn a GridCheckboxColumn but the underlying datatype is an int and it won't explicitly cast to bool even though the values are 0 or 1 in the database.
Any other suggestions?
0
Princy
Top achievements
Rank 2
answered on 27 Jan 2011, 10:51 AM
Hello Bill,

If you are using Inplace EditMode for child grid, please make the following modification in the above code and check if it works now. Also I feel sorry that I didnt convert the control into CheckBox type.

C#:
GridEditFormItem editedItem = e.Item as GridEditFormItem;
RadGrid dtlgrid = (editedItem.FindControl("grdClaimDetail") as RadGrid);
 foreach (GridEditFormItem childeditItem in RadGrid1.MasterTableView.GetItems(GridItemType.EditItem))
{
   CheckBox chk =(CheckBox) childeditItem.FindControl("chkResubmittedEdit"); //accessing CheckBox
}

Please paste your complete aspx code if it doesn't help?

Thanks,
Princy.
Tags
Grid
Asked by
Bill
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Bill
Top achievements
Rank 1
Share this question
or