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

how to add info to grid hierarchy

1 Answer 32 Views
Grid
This is a migrated thread and some comments may be shown as answers.
hugo
Top achievements
Rank 1
hugo asked on 26 Oct 2011, 12:58 AM
Hi all!!

I'm working with a RadGrid with hierarchies, but I have a couple of problems, I've managed to show the internal grids but when I display information in an internal grid I can not do depending on the value that has the grid father, my question is:
How I can make the relationship between parent and child grid?, And how to make each internal grid have different information?


Here is my code:

<telerik:RadGrid ID="grdCompCliente" runat="server" OnItemCommand="grdCompCliente_ItemCommand1"
                        OnItemCreated="grdCompCliente_ItemCreated1" 
                        OnItemDataBound="grdCompCliente_ItemDataBound1" Skin="Windows7">
                        <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default">
                        </HeaderContextMenu>
                        <MasterTableView AllowMultiColumnSorting="True" EnableNoRecordsTemplate="true" 
                            GroupLoadMode="Server" ShowHeadersWhenNoRecords="false">
                            <NestedViewTemplate>
                                <asp:Panel ID="InnerContainer" runat="server" Visible="false">
                                    <telerik:RadGrid ID="grdPostores" runat="server" >
                                        <MasterTableView AutoGenerateColumns = "true">
                                            <Columns>
                                                <telerik:GridBoundColumn DataField="Nombre" HeaderText="Nombre del Postor">
                                                </telerik:GridBoundColumn>
                                            </Columns>
                                        </MasterTableView>
                                    </telerik:RadGrid>
                                    <telerik:RadButton ID="cmdAgregarPostor" runat="server" 
                                        CausesValidation="False" Text="Agregar Postores">
                                    </telerik:RadButton>
                                </asp:Panel>
                            </NestedViewTemplate>
                            <CommandItemSettings ExportToPdfText="Export to PDF" />
                            <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column">
                            </RowIndicatorColumn>
                            <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column" 
                                Visible="True">
                            </ExpandCollapseColumn>
                            <EditFormSettings>
                                <EditColumn FilterControlAltText="Filter EditCommandColumn column">
                                </EditColumn>
                            </EditFormSettings>
                        </MasterTableView>
                        <FilterMenu EnableImageSprites="False">
                        </FilterMenu>
                    </telerik:RadGrid>

protected void grdCompCliente_ItemDataBound1(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridNestedViewItem)
            {                
                try
                {
                    int id = Convert.ToInt32(Session["Prueba"]);
                    DataAccesCatalogos compCliente = new DataAccesCatalogos();
                    ((RadGrid)e.Item.FindControl("grdPostores")).DataSource = compCliente.GetBidders(id);
                    ((RadGrid)e.Item.FindControl("grdPostores")).DataBind();
                }
                catch { }
            }
        }
         
        protected void grdCompCliente_ItemCreated1(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridNestedViewItem)
            {
                e.Item.FindControl("InnerContainer").Visible = ((GridNestedViewItem)e.Item).ParentItem.Expanded;
            }
        }
  
        protected void grdCompCliente_ItemCommand1(object sender, GridCommandEventArgs e)
        {
            if (e.CommandName == RadGrid.ExpandCollapseCommandName && e.Item is GridDataItem)
                {
                    ((GridDataItem)e.Item).ChildItem.FindControl("InnerContainer").Visible = !e.Item.Expanded;
                      
                    string id_comp = (e.Item as GridDataItem)["ID"].Text;
                      
                    Session["Prueba"] = id_comp;
                    //Label1.Text = "id: " + Session["Prueba"].ToString();
                }
             
        }

Thankyou for your attention

1 Answer, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 26 Oct 2011, 09:28 AM
Hello,

<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" OnNeedDataSource="RadGrid1_NeedDataSource"
           OnDetailTableDataBind="RadGrid1_DetailTableDataBind">
           <MasterTableView Name="ParentGrid" DataKeyNames="ID">
               <Columns>
                   <telerik:GridBoundColumn DataField="ID" HeaderText="ID" UniqueName="ID">
                   </telerik:GridBoundColumn>
                   <telerik:GridBoundColumn DataField="Name" HeaderText="Name" UniqueName="Name">
                   </telerik:GridBoundColumn>
               </Columns>
               <DetailTables>
                   <telerik:GridTableView Name="ChildGrid">
                       <Columns>
                           <telerik:GridBoundColumn DataField="ID" HeaderText="ID" UniqueName="ID">
                           </telerik:GridBoundColumn>
                           <telerik:GridBoundColumn DataField="Name" HeaderText="Name" UniqueName="Name">
                           </telerik:GridBoundColumn>
                       </Columns>
                   </telerik:GridTableView>
               </DetailTables>
           </MasterTableView>
            
       </telerik:RadGrid>
protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.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"}
            };
            RadGrid1.DataSource = data;
 
        }
 
        protected void RadGrid1_DetailTableDataBind(object sender, GridDetailTableDataBindEventArgs e)
        {
            GridDataItem item = e.DetailTableView.ParentItem as GridDataItem;
 
            string strID = item.GetDataKeyValue("ID").ToString();
 
            dynamic data = new[] {
                new { ID = 1, Name ="name11"},
                new { ID = 2, Name = "Name21"},
                new { ID = 3, Name = "name31"},
                new { ID = 4, Name = "Name41"},
                new { ID = 5, Name = "name51"}
            };
            e.DetailTableView.DataSource = data;
        }


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