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

Hierarchical RadGrid disappear after sorting main radgrid

2 Answers 97 Views
Grid
This is a migrated thread and some comments may be shown as answers.
ulas balkanlioglu
Top achievements
Rank 1
ulas balkanlioglu asked on 24 Aug 2011, 12:19 PM
I have a radgrid in NestedViewTemplate of a another radgrid. When main grid sorted the grid in NestedViewTemplate disappears. What may cause the loose of the data in nested grid ?

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 29 Aug 2011, 11:39 AM
Hello Ulas,

That is the default behavior of RadGrid. Anyway you can try the following code snippet which I have tried in my application to achieve the desired scenario. Hope it will help.

ASPX:
<telerik:RadGrid ID="RadGrid2" runat="server" DataSourceID="SqlDataSource1"
           AutoGenerateColumns="false" AllowSorting="true"
           onitemcommand="RadGrid2_ItemCommand" onprerender="RadGrid2_PreRender">
           <MasterTableView DataKeyNames="EmployeeID" CommandItemDisplay="Top">
               <Columns>
                  .  .  .   .
               </Columns>
               <NestedViewSettings DataSourceID="SqlDataSource1">
                   <ParentTableRelation>
                       <telerik:GridRelationFields DetailKeyField="EmpID" MasterKeyField="EmployeeID" />
                   </ParentTableRelation>
               </NestedViewSettings>
               <NestedViewTemplate>
                   <telerik:RadGrid ID="RadGrid3" runat="server" DataSourceID="SqlDataSource2" AutoGenerateColumns="false"
                       AllowAutomaticDeletes="true">
                       <MasterTableView DataKeyNames="EmpID">
                           <Columns>
                              .  .  .  .
                           </Columns>
                       </MasterTableView>
                   </telerik:RadGrid>
               </NestedViewTemplate>
          </MasterTableView>
      </telerik:RadGrid>

C#:
static int keyvalue = -1;
bool isSorted = false;
protected void RadGrid2_ItemCommand(object sender, GridCommandEventArgs e)
{
    if (e.CommandName == "ExpandCollapse")
    {
        if(!e.Item.Expanded)
        {
           GridDataItem item = (GridDataItem)e.Item;
           keyvalue =Convert.ToInt32(item.GetDataKeyValue("EmployeeID"));
        }
    }
    if (e.CommandName == "Sort")
    {
        isSorted = true;
    }
}
protected void RadGrid2_PreRender(object sender, EventArgs e)
{
    if (isSorted)
    {
        foreach (GridDataItem item in RadGrid2.Items)
        {
            if (Convert.ToInt32(item.GetDataKeyValue("EmployeeID")) == keyvalue)
            {
                item.Expanded = true;
                isSorted = false;
            }
        }
     }
}

Thanks,
Princy.
0
Andrey
Telerik team
answered on 29 Aug 2011, 11:44 AM
Hello Ulas Balkanlioglu,

Please elaborate a bit more about your scenario. What type of databinding are you using,  programmatic or declarative creation of RadGrid is performed? You can share some code snippets, or sample project.

Best wishes,
Andrey
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Tags
Grid
Asked by
ulas balkanlioglu
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Andrey
Telerik team
Share this question
or