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

Possible to have a RadGrid in a RadGrid?

5 Answers 309 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jon
Top achievements
Rank 1
Jon asked on 25 Oct 2010, 06:41 PM
Hi all,

I'm wondering if anyone knows if it's possible to have a RadGrid in RadGrid. Previously, I was able to do something similar where I had a DataList within a RadGrid column like so:

 

 

<telerik:GridTemplateColumn HeaderText="Keys" DataField="Keys">

 

 

 

<ItemTemplate>

 

 

 

<asp:DataList ID="DataList1" runat="server" DataSource='<%# Eval("Keys") %>'>

 

 

 

<ItemTemplate>

 

 

 

<asp:Label ID="Label1" runat="server" Text='<%# Eval("Number") %>'></asp:Label>

 

 

 

</ItemTemplate>

 

 

 

</asp:DataList>

 

 

 

</ItemTemplate>

 

 

 

</telerik:GridTemplateColumn>

 


Note, in this code, I used data binding with the DataSource property in DataList. I was thinking I could so something similar with RadGrid. However, I just realized that RadGrid has no DataSource property.

Has anyone ever tried putting a RadGrid in a column in another RadGrid? Is there a way to do it, or is this a known limitation?

Jon

5 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 26 Oct 2010, 11:34 AM
Hello Jon,

You can achieve this by accessing the grid inside ItemTemplate from code behind and set its dataSource like below.

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) // ItemDataBound Event of main grid
   {
     if (e.Item is GridDataItem)
       {
           GridDataItem item = (GridDataItem)e.Item;
           RadGrid childgrid = (RadGrid)item.FindControl("RadGrid3"); // accessing grid inside ItemTemplate
           childgrid.DataSource = dt; // setting DataSource
           childgrid.DataBind();
       }
   }

It is also possible to directly set the DataSourceID property of GridTableView in mark up to populate the grid.

ASPX:
<telerik:GridTemplateColumn>
  <ItemTemplate>
    <telerik:RadGrid ID="RadGrid3" runat="server" AutoGenerateColumns="True"
       GridLines="None" DataSourceID="SqlDataSource1">
        <MasterTableView>
            <Columns>
            </Columns>
         </MasterTableView>
    </telerik:RadGrid>
  </ItemTemplate>
</telerik:GridTemplateColumn>

Thanks,
Princy.
0
Jon
Top achievements
Rank 1
answered on 02 Nov 2010, 09:07 PM
I was able to get it to work partially by data binding using the DataSource property. I was mistaken before in saying that it didn't exist. It just wasn't listed by intellisense. I have it working as a viewable RadGrid. But, I want it to be editable. Does anyone know if there are any known issues with that. i.e. I have a RadGrid. I click the edit link on a given row. An in form edit screen appears within the RadGrid. This screen contains another RadGrid. The inner RadGrid is populated as it should be at this point. Now, if I click the edit link on the inner RadGrid, or the New record link, the RadGrid goes blank. Any ideas? Does anyone know if editing a RadGrid within another RadGrid works?
0
Jon
Top achievements
Rank 1
answered on 02 Nov 2010, 10:10 PM
Does anyone have example code for how to do a RadGrid in a RadGrid? Specifically, I want to do editing on both. I appreciate the previous sample code that was posted, but, it's not really sufficient for me to figure out how to do it, because I need to figure out how to bind to a property in the row that is being inserted or edited in the parent grid.

On a side note, is it just me, or is ASP.NET data binding a much bigger PITA than it should be? I REALLY wish Microsoft would revamp data binding in ASP.NET and make it work more like it does in Silverlight/WPF. IMHO it should work in a more POCO fashion. I never did like the way ASP.NET data binding seems to rely so heavily on DataSourceIDs and DataSources defined in markup. I'm not even sure defining things like queries in markup is a good idea to begin with. I'll cross my fingers and hope that maybe ASP.NET MVC handles this stuff better. That seems to be where Microsoft is focusing its effort these days.
0
Princy
Top achievements
Rank 2
answered on 03 Nov 2010, 08:56 AM
Hello,


I guess the problem might regarding the way you bind the grid. Are you using Simple DataBinding technique? If so, use NeedDataSource event to populate the iner grid as well the main grid. For more information check the demos below.
Grid / Advanced Data Binding

Update/Delete/Insert in grid:
Grid / Using Column Editors


Thanks,
Princy.
0
Jon
Top achievements
Rank 1
answered on 03 Nov 2010, 03:55 PM
At the moment, I'm using NeedDataSource on the outer RadGrid, and using the following binding on the inner grid, but, it's not working (view works, but, it goes blank when I click edit on the inner RadGrid). HostNames is a property in the particular row that I'm editing in the RadGrid.

DataSource='<%# Bind("HostNames") %>'

I'd like to use NeedDataSource on the inner one as well. The problem is, I don't know the Id of the row that I need to filter for. i.e. the inner RadGrid needs to bind to a collection in the currently editing or inserting row in the outer RadGrid.

Tags
Grid
Asked by
Jon
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Jon
Top achievements
Rank 1
Share this question
or