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

create radgrid inside other rad grid (hierarchy)

3 Answers 38 Views
Grid
This is a migrated thread and some comments may be shown as answers.
hugo
Top achievements
Rank 1
hugo asked on 14 Oct 2011, 07:25 PM
Hi all.

I have a question, Im currently working with radGrid and I need create hierarchy with this controls, but I need get data source from code-behind. In my first radgrid I can get data from code-behind but  I can't see the another radgrid in code.
I declared my two controls by this way:


<telerik:RadGrid ID="grdCompCliente" runat="server" Width="100%" Height="100px" OnItemDataBound="grdCompCliente_ItemDataBound1"
                   AutoGenerateColumns ="false" ShowGroupPanel="true">
                       <MasterTableView AllowMultiColumnSorting="True" >
                        
                       <NestedViewTemplate>
                       <asp:Panel runat="server" ID="InnerContainer" Visible="false">
                           <telerik:RadGrid  runat="server" ID="ID_Subasta" >
                               <MasterTableView>
                                  <Columns>
                                  <telerik:GridBoundColumn DataField="Id" HeaderText="ID">
                                    
                                  </telerik:GridBoundColumn>
                                  </Columns>
                               </MasterTableView>
                           </telerik:RadGrid>
                       </asp:Panel>
                       </NestedViewTemplate>
                            
                       </MasterTableView>
                   </telerik:RadGrid>


How can I do these?

Thank you for your attention!!

3 Answers, 1 is accepted

Sort by
0
Accepted
Jayesh Goyani
Top achievements
Rank 2
answered on 15 Oct 2011, 07:46 AM
Hello,

<telerik:RadGrid ID="grdCompCliente" runat="server" Width="100%" Height="100px" AutoGenerateColumns="false"
          ShowGroupPanel="true" OnNeedDataSource="grdCompCliente_NeedDataSource" OnItemDataBound="grdCompCliente_ItemDataBound">
          <MasterTableView AllowMultiColumnSorting="True" DataKeyNames="ID">
              <NestedViewTemplate>
                  <asp:Panel runat="server" ID="InnerContainer">
                      <telerik:RadGrid runat="server" ID="RadGrid1" OnNeedDataSource="RadGrid1_NeedDataSource">
                          <MasterTableView>
                              <Columns>
                                  <telerik:GridBoundColumn DataField="ID" HeaderText="ID">
                                  </telerik:GridBoundColumn>
                              </Columns>
                          </MasterTableView>
                      </telerik:RadGrid>
                  </asp:Panel>
              </NestedViewTemplate>
              <Columns>
                  <telerik:GridBoundColumn DataField="ID" HeaderText="ID">
                  </telerik:GridBoundColumn>
              </Columns>
          </MasterTableView>
      </telerik:RadGrid>
protected void grdCompCliente_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridNestedViewItem)
        {
             
            ((RadGrid)e.Item.FindControl("RadGrid1")).Rebind();
            // Another way to acieve this thing but you have to hadle pagging/sorting...etc your own way
            // if you want to assign datasource here then remove "RadGrid1_NeedDataSource" event
            //((RadGrid)e.Item.FindControl("RadGrid1")).DataSource = "";
 
        }
    }
 
    protected void grdCompCliente_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
    {
        dynamic data = new[] {
                new { ID = 1, Name ="Name1"},
                new { ID = 2, Name = "Name2"},
                new { ID = 3, Name = "Name3"},
                new { ID = 4, Name = "Name4"},
                new { ID = 5, Name = "Name5"}
            };
        grdCompCliente.DataSource = data;
    }
    protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
    {
        RadGrid RadGrid1 = sender as RadGrid;
        string ID = ((RadGrid1.NamingContainer as GridNestedViewItem).ParentItem as GridDataItem).GetDataKeyValue("ID").ToString();
 
        dynamic data = new[] {
                new { ID = 1, Name ="Name1" + ID},
                new { ID = 2, Name = "Name2"+ ID},
                new { ID = 3, Name = "Name3"+ ID},
                new { ID = 4, Name = "Name4"+ ID},
                new { ID = 5, Name = "Name5"+ ID}
            };
        RadGrid1.DataSource = data;
    }

let me know if any concern.

Thanks,
Jayesh Goyani
0
hugo
Top achievements
Rank 1
answered on 19 Oct 2011, 09:11 PM
Hi Jayesh Goyani

Thankyou for your answer.

But now I have another trouble; now I can fill twin RadGrid but I now can't expand and collapse to show them, how can I do that?? and how can I fill into rad grid with information diferent in each one

Thank you for your attention

0
Jayesh Goyani
Top achievements
Rank 2
answered on 20 Oct 2011, 01:17 PM
Hello,

Please elaborate your scenario or explain in detail or provide your code and let me know what you want.

Thanks,
Jayesh Goyani
Tags
Grid
Asked by
hugo
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
hugo
Top achievements
Rank 1
Share this question
or