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

Hierarchical RadGrid Databinding Issue

3 Answers 121 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Stephen Giordano
Top achievements
Rank 1
Stephen Giordano asked on 23 Nov 2011, 08:09 PM

Hello,

I have a 3-tier radgrid and I am using the DetailTableDataBind to set the SelectParameters of my ObjectDataSources.  I am having trouble on the third tier accessing the information correctly.  The data keys on the third tier contain all of the IDs I need for the datasource, but I could also get the keys from the first and second tier as they are the same.  But I cannot seem to get the syntax correct to do this.  My aspx and vb code are below.

ASPX:

<telerik:RadGrid ID="gvSites" DataSourceID="odsSiteList" runat="server" AutoGenerateColumns="False" GridLines="None">
    <MasterTableView DataSourceID="odsSiteList" DataKeyNames="ID" Name="Sites" EditMode="EditForms">                
        <DetailTables>
            <telerik:GridTableView CssClass="detail_table" DataSourceID="odsCategoryList" AutoGenerateColumns="false" DataKeyNames="ID" Name="Categories" AllowAutomaticInserts="true" AllowAutomaticUpdates="true" AllowAutomaticDeletes="true" CommandItemDisplay="Top" CommandItemSettings-AddNewRecordText="Add Category">
                <DetailTables>
                    <telerik:GridTableView CssClass="detail_table" DataSourceID="odsItemList" AutoGenerateColumns="false" DataKeyNames="Site_ID,Item_ID,Category_ID" Name="Items" AllowAutomaticInserts="true" AllowAutomaticUpdates="true" AllowAutomaticDeletes="true" CommandItemDisplay="Top" CommandItemSettings-AddNewRecordText="Add Item">

VB:

Private Sub gvSites_DetailTableDataBind(ByVal source As Object, ByVal e As GridDetailTableDataBindEventArgs) Handles gvSites.DetailTableDataBind
    Dim dataItem As GridDataItem = CType(e.DetailTableView.ParentItem, GridDataItem)
    If "Categories".Equals(e.DetailTableView.Name) Then
        odsCategoryList.SelectParameters("SiteID").DefaultValue = dataItem.GetDataKeyValue("ID").ToString()
    End If
    If "Items".Equals(e.DetailTableView.Name) Then
        odsItemList.SelectParameters("CategoryID").DefaultValue = dataItem.GetDataKeyValue("ID").ToString()
        odsItemList.SelectParameters("SiteID").DefaultValue = ???
    End If
End Sub

So my issue here is getting the SiteID.  It is the DataKey on the first-tier and it is also one of the DataKeys on the third-tier but I am not sure how to access it.  I either need to get the SiteID from the current levels ("Items") DataKeys or get the parent of the parent.

Thank you,

Steve

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 24 Nov 2011, 05:01 AM
Hello Stephen,

Try the following code snippet.
VB:
Protected Sub RadGrid2_DetailTableDataBind(sender As Object, e As GridDetailTableDataBindEventArgs)
    If e.DetailTableView.Name = "DetailTable1" Then
        Dim detailtabl1 As GridTableView = DirectCast(e.DetailTableView, GridTableView)
        Dim parentItem As GridDataItem = DirectCast(detailtabl1.ParentItem, GridDataItem)
             Dim customerId As String = parentItem.GetDataKeyValue("SiteID").ToString()
    End If
End Sub

-Shinu.
0
Stephen Giordano
Top achievements
Rank 1
answered on 06 Dec 2011, 09:53 PM
Hello,

Thank you for the reply but that is not working for me.  That is essentially the same code I am using to get the CategoryID because that is the datakey of the parent.  But the parent does not contain the SiteID.  Only the parent of the parent does and that is what I need to access.  So how do I go two levels up to get the datakey, essentially fromt he MasterTableView?  I tried this:

gvSites.MasterTableView.DataKeyValues(dataItem.ItemIndex)(

"ID").ToString

 


but it only works for the first row of the grid.

At the same time, the SiteID is also one of the datakeys of the current detailtable (level 3) so I could also just grab it from there if that was possible.

thanks,

Steve
0
Stephen Giordano
Top achievements
Rank 1
answered on 06 Dec 2011, 10:15 PM
Ok I figured out how to get the parent of the parent.

I got the parent datakey like this:

Dim

 

dataItem As GridDataItem = CType(e.DetailTableView.ParentItem, GridDataItem)

 

dataItem.GetDataKeyValue(

"ID").ToString()

 


SO to get the parent of the parent I did this:

dataItem.OwnerTableView.ParentItem.GetDataKeyValue(

"ID").ToString

 

Tags
Grid
Asked by
Stephen Giordano
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Stephen Giordano
Top achievements
Rank 1
Share this question
or