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

Codebehind to get 2 RadGrids to work togeather

1 Answer 12 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Perry
Top achievements
Rank 1
Perry asked on 03 Dec 2015, 05:58 PM

I have 2 RadGrids on the page one above the other

I use data entity for data source and The first RadGrid  data source is this

protected void RadGrid1_NeedDataSource(object sender, Web.UI.GridNeedDataSourceEventArgs e)
        {
            var result = from r in DbContext.LinkAnalysis
                         where r.LinkAnalysisCreator == dbuser
                         select r;
            RadGrid1.DataSource = result.ToList();
        }
 

The second Rad Grid Data source is this

 

protected void SubjectRadGrid_NeedDataSource(object sender, Web.UI.GridNeedDataSourceEventArgs e)
       {
            
           var results = from r in DbContext.Subjects
                         where r.LinkAnalysisId == linkId
                         select r;
           SubjectRadGrid.DataSource = results.ToList();
 
 
       }

When the page first loads the SubjectRadGrid shows no records.  This is okay but when a user clocks on one of the row in the RadGrid1 I want SubjectRadGrid to display the child objects for the selected row.

I obtain the "linkId" variable for the second RadGrid using this code

public void RadGrid1_SelectedIndexChanged(object sender, EventArgs e)
        {
            GridDataItem item = (GridDataItem)RadGrid1.SelectedItems[0];
            string ID = RadGrid1.SelectedValue.ToString();//Retrieving primary key field values for selected items
            linkId = Convert.ToInt16(ID);
 
            SubjectRadGrid.Rebind();
        }

This works works and if I place a break point in the SubjectRadGrid_NeedDataSource code I can see the data, during the Rebind, I need is being pulled.  But no data still does not show up in the SubjectRadGrid.

What am I missing here?

1 Answer, 1 is accepted

Sort by
0
Viktor Tachev
Telerik team
answered on 08 Dec 2015, 09:33 AM
Hello Perry,

The approach you describe should work. Please ensure that the EnablePostbackOnRowClick property of the first RadGrid is set to true. Also, you need to add the ID field to the DataKeyNames of the MasterTableView.

Check out the following online example that illustrates the approach. It uses SqlDataSource for binding the grids, however the main logic for retrieving the detail data would be similar in your scenario.



Regards,
Viktor Tachev
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Perry
Top achievements
Rank 1
Answers by
Viktor Tachev
Telerik team
Share this question
or