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

Updating mother grid the child grid disappeared

2 Answers 218 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Patrick
Top achievements
Rank 1
Patrick asked on 18 Feb 2013, 11:03 AM
Hi Team,

I had created 2 nested radgrid (with NestedViewTemplate method),  the mother grid contains 2 fields, team leader textbox and radcombox,
each mother grid has corresponding child grid with checkbox and the team member textbox. 

I want to update the items in mother grid for those checked items in child grid however the child grid turned out totally disappeared. 
I want to keep the child grid expanding and the checked box remains while I am updating the mother grid.  How can I do that.  Please advise.

Please find the photos for your reference.

Thanks.
Patrick

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 20 Feb 2013, 09:02 AM
Hi Patrick,

I guess you are rebinding the master grid after updating its value. So here is a sample code snippet which shows how to retain the expanded state with CheckBox in inner grid checked.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="SqlDataSource1" AutoGenerateColumns="false"
      OnPreRender="RadGrid1_PreRender">
      <MasterTableView DataKeyNames="CustomerID">
            <Columns>
              <telerik:GridTemplateColumn>
                  <ItemTemplate>
                      <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                  </ItemTemplate>
              </telerik:GridTemplateColumn>
          </Columns>
          <NestedViewSettings DataSourceID="SqlDataSource2">
              <ParentTableRelation>
                  <telerik:GridRelationFields DetailKeyField="CustomerID" MasterKeyField="CustomerID" />
              </ParentTableRelation>
          </NestedViewSettings>
          <NestedViewTemplate>
              <telerik:RadGrid ID="RadGrid2" runat="server" AutoGenerateColumns="false" DataSourceID="SqlDataSource2"
                  OnItemCommand="RadGrid2_ItemCommand" >
                  <MasterTableView DataKeyNames="CustomerID">
                      <Columns>
                          <telerik:GridTemplateColumn>
                              <ItemTemplate>
                                  <asp:CheckBox ID="CheckBox1" runat="server" />
                              </ItemTemplate>
                          </telerik:GridTemplateColumn>
                          <telerik:GridTemplateColumn>
                              <ItemTemplate>
                                  <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
                              </ItemTemplate>
                          </telerik:GridTemplateColumn>
                          <telerik:GridButtonColumn Text="update" CommandName="update">
                          </telerik:GridButtonColumn>
                      </Columns>
                  </MasterTableView>
              </telerik:RadGrid>
          </NestedViewTemplate>
         </MasterTableView>
    </telerik:RadGrid>

CS:
public static int rowIndex=-1;
public static int childRowIndex = -1;
 
protected void RadGrid2_ItemCommand(object sender, GridCommandEventArgs e)
{
    if (e.CommandName == "update")
    {
        GridDataItem item = (GridDataItem)e.Item;
        childRowIndex = item.ItemIndex;//row index of child item
        RadGrid grid = (RadGrid)sender;
        GridNestedViewItem nestedItem = (GridNestedViewItem)grid.NamingContainer;
        GridDataItem parentItem = (GridDataItem)nestedItem.ParentItem;
        rowIndex = parentItem.ItemIndex;//row index of parent item
        //performing some db operations and binding parent grid (RadGrid1)
        RadGrid1.Rebind();
    }
}
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
    if (rowIndex > -1)
    {
        GridDataItem masterTableItem = (GridDataItem)RadGrid1.MasterTableView.Items[rowIndex]; // Get the mastertable item 
        masterTableItem.Expanded = true; // Expand the item
        GridNestedViewItem nestedViewItem = (GridNestedViewItem)RadGrid1.MasterTableView.GetItems(GridItemType.NestedView)[rowIndex];
        RadGrid nestedgrid = (RadGrid)nestedViewItem.FindControl("RadGrid2");
        GridDataItem item = (GridDataItem)nestedgrid.Items[childRowIndex];// Get the child item 
        CheckBox chkbox = (CheckBox)item.FindControl("CheckBox1");
        chkbox.Checked = true;//make the CheckBox selected
        rowIndex=-1;
        childRowIndex = -1;
    }
}

Thanks,
Princy.
0
Patrick
Top achievements
Rank 1
answered on 01 Mar 2013, 08:01 AM
Hi Princy,

Thanks.  It is solved.

Regards,
Patrick
Tags
Grid
Asked by
Patrick
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Patrick
Top achievements
Rank 1
Share this question
or