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

Using griddata in grid under nestedview

2 Answers 38 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ahrensberg
Top achievements
Rank 1
Ahrensberg asked on 15 Dec 2009, 09:16 AM
Hi all,

I have a grid containing orders with IDs. This main grid have a nestedview in which I have a tab containing some text and another containing a new grid with the orderlines.

How can I give the information about the order id to the grid containing the orderlines. My code looks something like beneath (I have cutted out a lot of code to get a better overview of the essential code):

<telerik:RadGrid ID="RgOrders" AutoGenerateColumns="false" OnNeedDataSource="RgOrders_NeedDataSource" runat="server"
    <MasterTableView ClientDataKeyNames="id"
        <Columns> 
            <telerik:GridBoundColumn DataField="OrderNumber" HeaderText="OrderNumber" UniqueName="OrderNumber" /> 
            <telerik:GridBoundColumn DataField="OrderFirstName" HeaderText="OrderFirstName" UniqueName="OrderFirstName" /> 
            <telerik:GridBoundColumn DataField="OrderLastName" HeaderText="OrderLastName" UniqueName="OrderLastName" /> 
        </Columns> 
        <NestedViewTemplate> 
            <asp:Panel runat="server" ID="OrderNestedView" Visible="false"
                <telerik:RadTabStrip runat="server" ID="TabStrip1" Visible="true" SelectedIndex="0" MultiPageID="Multipage1" Align="Justify"
                    <Tabs> 
                        <telerik:RadTab runat="server" Text="OrderInformation" PageViewID="PageViewOrderInformation"
                        </telerik:RadTab> 
                        <telerik:RadTab runat="server" Text="OrderLines" PageViewID="PageViewOrderLines"
                        </telerik:RadTab> 
                    </Tabs> 
                </telerik:RadTabStrip> 
                <telerik:RadMultiPage runat="server" ID="Multipage1" SelectedIndex="0" RenderSelectedPageOnly="false"
                    <telerik:RadPageView runat="server" ID="PageViewOrderInformation"
                        [... some orderinformation ...] 
                    </telerik:RadPageView> 
                    <telerik:RadPageView runat="server" ID="PageViewOrderLines"
                        <telerik:RadGrid ID="RgOrderLines" AutoGenerateColumns="false" OnNeedDataSource="RgOrderLines_NeedDataSource" runat="server"
                            <MasterTableView> 
                                <Columns> 
                                    <telerik:GridBoundColumn DataField="OrderLineNumber" HeaderText="OrderLineNumber" UniqueName="OrderLineNumber" /> 
                                    [... some more GridBoundColumn ...] 
                                </Columns> 
                            </MasterTableView> 
                        </telerik:RadGrid> 
                    </telerik:RadPageView> 
                </telerik:RadMultiPage> 
            </asp:Panel> 
        </NestedViewTemplate> 
    </MasterTableView> 
</telerik:RadGrid> 



2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 1
answered on 15 Dec 2009, 11:26 AM
Hi,

You can access the DataKeyValue field of the main grid in the NeedDataSource event of the nested grid as shown in the example below:
aspx:
<telerik:RadGrid ID="RadGrid1" AutoGenerateColumns="false" OnNeedDataSource="RadGrid1_NeedDataSource" runat="server">  
    <MasterTableView DataKeyNames="ID">  
        <Columns>  
           ....  
        </Columns>  
        <NestedViewTemplate>  
            <asp:Panel runat="server" ID="NestedPanel" Visible="false">  
                <telerik:RadTabStrip runat="server" ID="RadTabStrip1" Visible="true" SelectedIndex="0" MultiPageID="Multipage1">  
                    <Tabs>  
                        <telerik:RadTab runat="server" Text="Tab1" PageViewID="PageView1">  
                        </telerik:RadTab>  
                        <telerik:RadTab runat="server" Text="Tab2" PageViewID="PageView2">  
                        </telerik:RadTab>  
                    </Tabs>  
                </telerik:RadTabStrip>  
                <telerik:RadMultiPage runat="server" ID="RadMultipage1" SelectedIndex="0" RenderSelectedPageOnly="false">  
                    <telerik:RadPageView runat="server" ID="PageView1">  
                       .... 
                    </telerik:RadPageView>  
                    <telerik:RadPageView runat="server" ID="PageView2">  
                        <telerik:RadGrid ID="RadGrid2" AutoGenerateColumns="false" OnNeedDataSource="RadGrid2_NeedDataSource" runat="server">  
                            <MasterTableView>  
                                <Columns>  
                                   ...  
                                </Columns>  
                            </MasterTableView>  
                        </telerik:RadGrid>  
                    </telerik:RadPageView>  
                </telerik:RadMultiPage>  
            </asp:Panel>  
        </NestedViewTemplate>  
    </MasterTableView>  
</telerik:RadGrid>  

c#:
 protected void RadGrid2_NeedDataSource(object source, GridNeedDataSourceEventArgs e) 
    { 
        RadGrid grid = (RadGrid)source;         
        GridNestedViewItem nestedview = (GridNestedViewItem)grid.NamingContainer; 
        string strtxt = ((GridDataItem)(nestedview.ParentItem)).GetDataKeyValue("ID").ToString(); 
        //... 
    } 

Thanks
Princy.
0
Ahrensberg
Top achievements
Rank 1
answered on 15 Dec 2009, 12:26 PM
Perfect!

Thank you :o)
Tags
Grid
Asked by
Ahrensberg
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Ahrensberg
Top achievements
Rank 1
Share this question
or