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

Radgrid inside TemplateItem in another Radgrid

2 Answers 77 Views
Grid
This is a migrated thread and some comments may be shown as answers.
saritha78
Top achievements
Rank 1
saritha78 asked on 05 Nov 2011, 01:53 AM
I need to display rows of data, where one of the columns is also rows of data. How can I achieve this with one call to get the data.

The data received from data layer looks like this, it is one call to GetData() and it returns
List<Customer> customers where customer.Products= List<Product>

and I would like to display it as

CustomerId  CustomerName         Products
1 John Smith                 Paper 12.50
                                                        Pin        1.99
                                                        Clip       5.55
              Jane Doe                   Paper    15.55
                                                        Pin           2.99


Can I achieve this display using two RadGrids?
Thanks,

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 07 Nov 2011, 09:12 AM
Hello Saritha,

You can add the RadGrid in ItemTemplate of first RadGrid. Here is the sample code to achieve the same.

C#:
protected void RadGrid2_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{       
   RadGrid RadGrid2 = sender as RadGrid;
   GridDataItem item = RadGrid2.NamingContainer as GridDataItem;   // accessing the parent row. 
   string id= item.GetDataKeyValue("EmployeeID").ToString(); // accessing the parent DataKeyValue
   string s = "select EmployeeID,TerritoryID from EmployeeTerritories where EmployeeId='"+id+"'"; //build your query.
   con.Open();
   SqlDataAdapter dr = new SqlDataAdapter(s, con);
   DataTable dt = new DataTable();
   dr.Fill(dt);  
   RadGrid2.DataSource = dt;
   con.Close();
 }

Thanks,
Princy.
0
saritha78
Top achievements
Rank 1
answered on 07 Nov 2011, 05:53 PM
Hi Princy, 
Thanks for your reply. But I dont think you got what my problem is. 
I have an IEnumerable list of custom DTO objects (Customer in my example) as my datasource. I am not using SQL datasource. And the List of objects has a property which is also an IEnumerable list of another DTO object (Products in my example). And I get this one big list from one call to the Data Layer. How do I bind it to a Radgrid in one go so that it is displayed as I first posted ?
Thanks,
Tags
Grid
Asked by
saritha78
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
saritha78
Top achievements
Rank 1
Share this question
or