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

[Solved] Another question about the Hierarchy with Template demo

1 Answer 119 Views
Grid
This is a migrated thread and some comments may be shown as answers.
andieje
Top achievements
Rank 1
andieje asked on 21 May 2009, 10:16 PM

Hi

I'm using Q3    2008 release

I have been trying to emulate the hierarchy with template demo. I am using the Northwind database. My master table contains customers in the database. 

 I have been able to create a NestedViewTemplate that contains a hidden label containing the primary key for the parent row. I then use this row as a control parameter in an sql data source to populate a radgrid nested inside the NestedViewTemplate with orders for the customer ( i know i could use a standard master detail table for this but because of a layout demands I need to investigate this NestedViewTemplate). I have been able to populate the nested radgrid declaratively but I would like to know how to populate it programmatically. I have played around in the detail table data bind event to try and find some way to access the controls in the NestedViewTemplate but to no avail.

 

I have pasted the code below for the declarative 'version' which works ok

 

Many thanks in advace

<

 

asp:ScriptManager ID="ScriptManager1" runat="server">

 

 

 

 

 

</asp:ScriptManager>

 

 

 

 

 

<telerik:RadGrid ID="RadGrid1" runat="server" >

 

 

 

 

 

<MasterTableView DataKeyNames="CustomerID" >

 

 

 

 

 

<ExpandCollapseColumn Visible="True">

 

 

 

 

 

</ExpandCollapseColumn>

 

 

 

 

 

<NestedViewTemplate>

 

 

 

 

 

 

<telerik:RadTabStrip runat="server" ID="TabStrip1" MultiPageID="Multipage1"

 

 

 

 

 

SelectedIndex="0">

 

 

 

 

 

<Tabs>

 

 

 

 

 

<telerik:RadTab runat="server" Text="Orders" PageViewID="PageView1">

 

 

 

 

 

</telerik:RadTab>

 

 

 

 

 

<telerik:RadTab runat="server" Text="Contact Information" PageViewID="PageView2">

 

 

 

 

 

</telerik:RadTab>

 

 

 

 

 

<telerik:RadTab runat="server" Text="Statistics Chart" PageViewID="PageView3">

 

 

 

 

 

</telerik:RadTab>

 

 

 

 

 

</Tabs>

 

 

 

 

 

</telerik:RadTabStrip>

 

 

 

 

 

<telerik:RadMultiPage runat="server" ID="Multipage1" RenderSelectedPageOnly="false">

 

 

 

 

 

<telerik:RadPageView runat="server" ID="PageView1">

 

 

 

 

 

<asp:Label ID="Label1" Font-Bold="true" Font-Italic="true" Text='<%# Eval("CustomerID") %>'

 

 

 

 

 

runat="server" />

 

 

 

 

PageView 1

 

 

 

 

<telerik:RadGrid runat="server" ID="RadGrid2">

 

 

 

 

 

<MasterTableView DataSourceID="SqlDataSource2">

 

 

 

 

 

<Columns>

 

 

 

 

 

<telerik:GridBoundColumn DataField="OrderDate"></telerik:GridBoundColumn>

 

 

 

 

 

</Columns>

 

 

 

 

 

</MasterTableView>

 

 

 

 

 

</telerik:RadGrid>

 

 

 

 

 

 

<asp:SqlDataSource ID="SqlDataSource2" ConnectionString="Data Source=OSCAR\SQLExpress;Initial Catalog=Northwind;Integrated Security=true;"

 

 

 

 

 

ProviderName="System.Data.SqlClient" SelectCommand="SELECT * FROM Orders Where CustomerID = @CustomerID"

 

 

 

 

 

runat="server">

 

 

 

 

 

 

<SelectParameters>

 

 

 

 

 

<asp:ControlParameter ControlID="Label1" PropertyName="Text" Type="String" Name="CustomerID" />

 

 

 

 

 

</SelectParameters>

 

 

 

 

 

 

</asp:SqlDataSource>

 

 

 

 

 

</telerik:RadPageView>

 

 

 

 

 

</telerik:RadMultiPage>

 

 

 

 

 

</NestedViewTemplate>

 

 

 

 

 

 

</MasterTableView>

 

 

 

 

 

</telerik:RadGrid>

 

 

 

 

 

 

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 22 May 2009, 06:00 AM
Hello,

You can access the NestedViewItem and thereby the nested grid and set its DataSource in the PreRender event as shown below:
 protected void RadGrid1_PreRender(object sender, EventArgs e) 
    { 
 
        foreach (GridDataItem item in RadGrid1.MasterTableView.Items) 
        { 
            if (item.Expanded) 
            { 
 
                foreach (GridNestedViewItem item1 in RadGrid1.MasterTableView.GetItems(GridItemType.NestedView)) 
                { 
                    RadGrid grid = (RadGrid)item1.FindControl("RadGrid2"); 
                    grid.DataSourceID = "SqlDataSource2"
                } 
 
            } 
 
        } 

Thanks
Princy.
Tags
Grid
Asked by
andieje
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or