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

DetailTableDataBind Called Multiple Times

2 Answers 179 Views
Grid
This is a migrated thread and some comments may be shown as answers.
David Kucharski
Top achievements
Rank 1
David Kucharski asked on 29 Apr 2013, 03:38 PM
I have a radGrid that I create in the Page_Init. Below is my structure. In it you will see I have 4 items that make up my DataKeys. I also, at the bottom, create a GridTableView. That view has 5 items that make up my DayKey. The 4 same from above and 1 extra. I create 4 GridRelationFields. When I do this, my RadGrid1_DetailTableDataBind method gets called 4 times for each parent item. What am I doing wrong? I would have thought the RadGrid1_DetailTableDataBind would be called only once for each parent.

Page_Init
RadGrid1.ID = "RadGrid1"
RadGrid1.Width = Unit.Pixel(1500)
RadGrid1.MasterTableView.EditMode = GridEditMode.InPlace
RadGrid1.AllowPaging = True
RadGrid1.PagerStyle.Mode = GridPagerMode.NextPrevAndNumeric
RadGrid1.AutoGenerateColumns = False
RadGrid1.ShowStatusBar = True
RadGrid1.AllowSorting = True
RadGrid1.AllowFilteringByColumn = True
RadGrid1.Skin = "WebBlue"
RadGrid1.ClientSettings.ClientEvents.OnGridCreated = "GetGridObject"
RadGrid1.ClientSettings.Scrolling.FrozenColumnsCount = 2
RadGrid1.ClientSettings.AllowColumnsReorder = True
RadGrid1.ClientSettings.ColumnsReorderMethod = GridClientSettings.GridColumnsReorderMethod.Swap
RadGrid1.ClientSettings.Selecting.AllowRowSelect = True
RadGrid1.ClientSettings.Resizing.AllowColumnResize = True
RadGrid1.ClientSettings.Scrolling.AllowScroll = True
RadGrid1.ClientSettings.Scrolling.UseStaticHeaders = True
RadGrid1.ClientSettings.Scrolling.SaveScrollPosition = True
RadGrid1.MasterTableView.PageSize = 100
RadGrid1.MasterTableView.AllowMultiColumnSorting = True
RadGrid1.MasterTableView.DataKeyNames = New String() {"VendorListID", "Geography", "CirculationTypeID", "Day"}
columnCreation("Geography", "Geography", RadGrid1)
columnCreation("Circ Type", "CirculationTypeDescription", RadGrid1)
columnCreation("Household", "HouseHold_Count", RadGrid1)
columnCreation("Total Cov", "TotalCoverage", RadGrid1)
columnCreation("Day", "Day", RadGrid1)
columnCreation("Selected", "Selected", RadGrid1)
columnCreation("Circ", "Circ", RadGrid1)
columnCreation("Coverage", "Coverage", RadGrid1)
columnCreation("Zones", "Zones", RadGrid1)
RadGrid1.MasterTableView.HierarchyDefaultExpanded = True
Dim tableSubCode As New GridTableView(RadGrid1)
tableSubCode.Name = "SubCodes"
tableSubCode.DataKeyNames = New String() {"VendorListID", "Geography", "CirculationTypeID", "Day", "Sub_Code"}
tableSubCode.Width = Unit.Percentage(100)
Dim relationFields1 As GridRelationFields = New GridRelationFields()
relationFields1.MasterKeyField = "VendorListID"
relationFields1.DetailKeyField = "VendorListID"
tableSubCode.ParentTableRelation.Add(relationFields1)
RadGrid1.MasterTableView.DetailTables.Add(tableSubCode)
Dim relationFields2 As GridRelationFields = New GridRelationFields()
relationFields2.MasterKeyField = "Geography"
relationFields2.DetailKeyField = "Geography"
tableSubCode.ParentTableRelation.Add(relationFields2)
RadGrid1.MasterTableView.DetailTables.Add(tableSubCode)
Dim relationFields3 As GridRelationFields = New GridRelationFields()
relationFields3.MasterKeyField = "CirculationTypeID"
relationFields3.DetailKeyField = "CirculationTypeID"
tableSubCode.ParentTableRelation.Add(relationFields3)
RadGrid1.MasterTableView.DetailTables.Add(tableSubCode)
Dim relationFields4 As GridRelationFields = New GridRelationFields()
relationFields4.MasterKeyField = "Day"
relationFields4.DetailKeyField = "Day"
tableSubCode.ParentTableRelation.Add(relationFields4)
RadGrid1.MasterTableView.DetailTables.Add(tableSubCode)
columnSubCodeCreation("SubCode", "Sub_Code", tableSubCode)
columnSubCodeCreation("Household", "HouseHold_Count", tableSubCode)
columnSubCodeCreation("Selected", "Selected", tableSubCode)
columnSubCodeCreation("Circ", "Circ", tableSubCode)
columnSubCodeCreation("Coverage", "Coverage", tableSubCode)
Me.PlaceHolder1.Controls.Add(RadGrid1)

RadGrid1_DetailTableDataBind

Dim dataItem As GridDataItem = CType(e.DetailTableView.ParentItem, GridDataItem)
Select Case e.DetailTableView.Name
    Case "SubCodes"
        Dim vendorListID As Integer = dataItem.GetDataKeyValue("VendorListID").ToString()
        Dim Geography As String = dataItem.GetDataKeyValue("Geography").ToString()
        Dim CirculationTypeID As Integer = dataItem.GetDataKeyValue("CirculationTypeID").ToString()
        Dim Day As String = dataItem.GetDataKeyValue("Day").ToString()
        If mintCircSetID > 0 Then
            e.DetailTableView.DataSource = GetDataTable(mstrSQL & ",1,'" & Geography & "'," & CirculationTypeID & ",'" & Day & "'")
        End If
End Select

2 Answers, 1 is accepted

Sort by
0
Accepted
Angel Petrov
Telerik team
answered on 02 May 2013, 11:17 AM
Hi David,

When using the OnDetailTableDataBind event there is no need to set GridRelationFields as you can obtain the value needed for populating the child table directly from the parent item. I suggest that you review this help article which explains in detail how the hierarchical data-binding using DetailTableDataBind event works. Please modify your logic according to the help article and tell us if the problem still replicates.

All the best,
Angel Petrov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
David Kucharski
Top achievements
Rank 1
answered on 02 May 2013, 01:31 PM
Thanks Angel. That did the trick.
Tags
Grid
Asked by
David Kucharski
Top achievements
Rank 1
Answers by
Angel Petrov
Telerik team
David Kucharski
Top achievements
Rank 1
Share this question
or