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

[Solved] Nested Grids Datasource Trouble

2 Answers 116 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rocky
Top achievements
Rank 1
Rocky asked on 10 Sep 2009, 10:20 PM

<telerik:RadGrid  ID="RadGrid1" runat="server" 
        AllowPaging="True" GridLines="None"   
        AllowSorting="True" Skin="Office2007" AllowAutomaticUpdates="True" AutoGenerateColumns="False" 
        OnUpdateCommand="RadGrid1_UpdateCommand" OnNeedDataSource="RadGrid1_NeedDataSource" 
        OnItemCommand="RadGrid1_ItemCommand" OnItemCreated="RadGrid1_ItemCreated" OnPreRender="RadGrid1_PreRender">  
          
        <PagerStyle Mode="NumericPages" /> 
        <MasterTableView AllowMultiColumnSorting="True" DataKeyNames="BillingItemID" > 
                  
            <NestedViewTemplate> 
                <asp:Panel runat="server" ID="InnerContainer" Visible="false">  
 
                    <telerik:RadMultiPage runat="server" ID="Multipage1" SelectedIndex="0" RenderSelectedPageOnly="false">  
                        <telerik:RadPageView runat="server" ID="PageView1">  
                            <asp:Label ID="BillingItemAssociationID" Text='<%# Eval("BillingItemAssociationID") %>' Visible="false" runat="server" /> 
                              
                            <telerik:RadGrid ID="ChildGrid" runat="server" OnNeedDataSource="ChildGrid_NeedDataSource" OnUpdateCommand="RadGrid1_UpdateCommand" OnItemCreated="RadGrid1_ItemCreated" AllowAutomaticUpdates="true" ShowFooter="true" AllowSorting="true">  
                              
                                <MasterTableView ShowHeader="true" AutoGenerateColumns="False" AllowPaging="true" DataKeyNames="BillingItemID" PageSize="10" HierarchyLoadMode="ServerOnDemand">  
                                          
                                    <Columns> 
protected void RadGrid2_NeedDataSource(object source, GridNeedDataSourceEventArgs e)  
        {  
            ((RadGrid)source).DataSource = BillingItemsChildData(id);  
        } 

I've set the OnNeedDataSource attribute in the nested grid but it's getting called at the right times! The only way I can get this to work is to use a SqlDatasource in the .aspx file and that's just not an option for me. Also You see i'm sending the id (datakey) to the

BillingItemsChildData method but i'm not able to get the datakey from the parent inside this event. I've been testing by manually setting it.

I've been stuck on this for a while now. People on here have suggested that I use the detailsgridbind event but it's not a details grid, it's a nested radgrid.

I've tried setting the NeedDataSource event programmaticaly in just about every event in the page lifecycle and nothing works, only the .aspx SqlDataSource.

Thanks in advance.

2 Answers, 1 is accepted

Sort by
0
Suresh K
Top achievements
Rank 1
answered on 11 Sep 2009, 07:14 AM



 protected void RadGrid1_PreRender(object sender, EventArgs e) 
    { 
        Telerik.Web.UI.RadGrid Radgrd = default(Telerik.Web.UI.RadGrid); 
         string dataval = null
         foreach (GridDataItem item in RadGrid1.MasterTableView.Items) 
         { 
         dataval = item.GetDataKeyValue("keyval").ToString(); 
         foreach (var item1 in RadGrid1.MasterTableView.GetItems(GridItemType.NestedView)) 
         { 
             Radgrd = (Telerik.Web.UI.RadGrid)item1.FindControl("ChildGrid"); 
             Radgrd.DataSource = getdata("SqlQuery"); 
             Radgrd.DataBind(); 
         } 
     } 
    } 
     
 
    protected DataSet getdata(string query) 
    { 
        con.Open(); 
        cmd = new SqlCommand(query, con); 
        myda = new SqlDataAdapter(cmd); 
        ds = new DataSet(); 
        myda.Fill(ds); 
        con.Close(); 
        return ds; 
   } 

Can u try this
0
Rocky
Top achievements
Rank 1
answered on 11 Sep 2009, 12:48 PM

I've tried that already. I resolved this by removing some funtionality in my grid. I removed the nested grid tag. This was unfortunate, but I couldn't spent anymore time on this.

    <telerik:RadGrid  ID="RadGrid1" runat="server" 
        AllowPaging="True" GridLines="None"   
        AllowSorting="True" Skin="Office2007" AllowAutomaticUpdates="True" AutoGenerateColumns="False" 
        OnUpdateCommand="RadGrid1_UpdateCommand" OnNeedDataSource="RadGrid1_NeedDataSource" OnPreRender="RadGrid1_PreRender" OnDetailTableDataBind="RadGrid1_DetailTableDataBind">  
          
        <PagerStyle Mode="NumericPages" /> 
        <MasterTableView AllowMultiColumnSorting="True" DataKeyNames="BillingItemID">  
                  
            <DetailTables> 
                <telerik:GridTableView HierarchyLoadMode="ServerBind" DataKeyNames="BillingItemID"
Tags
Grid
Asked by
Rocky
Top achievements
Rank 1
Answers by
Suresh K
Top achievements
Rank 1
Rocky
Top achievements
Rank 1
Share this question
or