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

[Solved] NeedDataSource in Nested Grid

1 Answer 222 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rocky
Top achievements
Rank 1
Rocky asked on 09 Sep 2009, 04:18 PM
Could someone give me an example of a nested grid using the NeedDataSource event that takes datakey from the parent grid? I don't want to use the SqlDatasource. Also where would I register this event? It seems that just setting the nested grids OnNeedDataSource attrib doesn't do it.

Thanks
Rocky

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 10 Sep 2009, 08:09 AM
Hi Rocky,

You could use the DetailTableDataBind event which fires when a table from DetailTablesCollection binds to a data source. You can pass the DataKeyValue to the query string to populate the detail table.

CS:
 
protected void RadGrid1_DetailTableDataBind(object source, Telerik.Web.UI.GridDetailTableDataBindEventArgs e) 
    { 
        if (e.DetailTableView.Name == "Detail1"
        { 
            string strtxt = e.DetailTableView.ParentItem.GetDataKeyValue("EmployeeID").ToString(); // Where set the DataKeyNames of MasterTableView as EmployeeID 
            e.DetailTableView.DataSource = GetDataTable("SELECT EmployeeID,BirthDate, HireDate FROM Employees"+"WHERE EmployeeID='"+strtxt+"'"); //GetDataTable returns the DataTable according to query string passed 
        }        
    } 

-Shinu.
Tags
Grid
Asked by
Rocky
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or