I am creating a RadGrid in my Page_Init. Intially when the screen first comes up the hierarchy will not be defined. When the user clicks on a button, the page will refresh and in certail cases I will want the grid to have hierarchy and it others not. The problem is when the page_init first fires and the grid is created with no hierarchy. Then the user clicks, page_init fires and the code to add hierarchy runs with no errors. The page displays but no hierarchy is shown. The DetailTableDataBind does not even fire. If I set up the hierarchy when the page first loads and then the user clicks the button, the hierarchy shows. I must be doing something wrong in code to have my changes not applied. Please let me know.
I declare a RadGrid1 in my .aspx.vb page
I declare a placeholder on my aspx page
In my page_init i call the defineGridStructure. I check the variable mSubCodesAvailable in 2 places to setup my hierarchy.
Again, if I comment out the IF part so the hierarchy gets setup initially, all is good. It is when the grid does not setup hierarchy on the first page_init, but tries to set it up on the second page_init that the hierarchy does not work.
I have my 2 procedures to fill my RadGrid1
in my Page_Load I do the following
I declare a RadGrid1 in my .aspx.vb page
Private WithEvents RadGrid1 As RadGrid = New RadGrid()<table id="tblTelerikDetails" cellpadding="0" cellspacing="0" width="1500" style="background-color:white" border="1"> <tr> <td> <asp:PlaceHolder EnableViewState="false" ID="PlaceHolder1" runat="server" /> </td> </tr> </table> Again, if I comment out the IF part so the hierarchy gets setup initially, all is good. It is when the grid does not setup hierarchy on the first page_init, but tries to set it up on the second page_init that the hierarchy does not work.
Private Sub defineGridStructure() RadGrid1.ID = "RadGrid1" RadGrid1.Width = Unit.Pixel(1500) RadGrid1.Height = Unit.Pixel(700) 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.EnableViewState = False RadGrid1.MasterTableView.PageSize = 50 RadGrid1.MasterTableView.AllowMultiColumnSorting = True RadGrid1.MasterTableView.DataKeyNames = New String() {"DetailID", "Day"} If mSubCodesAvailable Then RadGrid1.MasterTableView.HierarchyLoadMode = GridChildLoadMode.ServerBind RadGrid1.MasterTableView.HierarchyDefaultExpanded = True End If columnCreation("Geography", "Geography", RadGrid1) columnCreation("Circ Type", "CirculationTypeDescription", RadGrid1) columnCreation("Household", "HouseHold_Count", RadGrid1) columnCreation("Total Cov", "TotalCoverage", RadGrid1) If miZipCodeStoreAssociationTypeID > 0 Then columnCreation("Location Market", "LocationMarket", RadGrid1) columnCreation("Location Number", "LocationNumber", RadGrid1) columnCreation("Location Name", "LocationName", RadGrid1) columnCreation("Distance", "Distance", RadGrid1) columnCreation("Sales", "Sales", RadGrid1) columnCreation("Total Sales", "TotalSales", RadGrid1) columnCreation("BOS", "BOS", RadGrid1) columnCreation("Cume BOS", "CumeBOS", RadGrid1) columnCreation("SPH", "SPH", RadGrid1) columnCreation("SPH Index", "SPHIndex", RadGrid1) End If If mstrClientDataCategoryID1Description.Trim <> "" Then columnCreation(mstrClientDataCategoryID1Description.Trim, "CD1", RadGrid1) End If If mstrClientDataCategoryID2Description.Trim <> "" Then columnCreation(mstrClientDataCategoryID2Description.Trim, "CD2", RadGrid1) End If If mstrClientDataCategoryID3Description.Trim <> "" Then columnCreation(mstrClientDataCategoryID3Description.Trim, "CD3", RadGrid1) End If If mstrReportDemographicID1Description.Trim <> "" Then columnCreation(mstrReportDemographicID1Description.Trim, "Demographic1", RadGrid1) End If If mstrReportDemographicID2Description.Trim <> "" Then columnCreation(mstrReportDemographicID2Description.Trim, "Demographic2", RadGrid1) End If If mstrReportDemographicID3Description.Trim <> "" Then columnCreation(mstrReportDemographicID3Description.Trim, "Demographic3", RadGrid1) End If If mstrReportDemographicID4Description.Trim <> "" Then columnCreation(mstrReportDemographicID4Description.Trim, "Demographic4", RadGrid1) End If If mstrReportDemographicID5Description.Trim <> "" Then columnCreation(mstrReportDemographicID5Description.Trim, "Demographic5", RadGrid1) End If columnCreation("Day", "Day", RadGrid1) columnCreation("Selected", "Selected", RadGrid1) If UcHeader.objSession.ApplicationId <> CInt(ConfigurationManager.AppSettings("MediaviewerAppID")) Then columnCreation("Forced", "Forced", RadGrid1) End If columnCreation("Circ", "Circ", RadGrid1) columnCreation("Coverage", "Coverage", RadGrid1) columnCreation("Zones", "Zones", RadGrid1) If UcHeader.objSession.ApplicationId <> CInt(ConfigurationManager.AppSettings("MediaviewerAppID")) Then If miVersionsCategoryID > 0 Then columnCreation("Version", "Version", RadGrid1) columnCreation("Sub-Version Category", "SubVersionCategory", RadGrid1) End If If miDeliveryCodeCount > 0 Then columnCreation("Delivery Code", "DeliveryCode", RadGrid1) End If Dim dpCounter As Integer = 1 Dim dpCollection As IList(Of RadListBoxItem) = rlbDistributionPatterns.CheckedItems For Each item As RadListBoxItem In dpCollection columnCreation(item.Text, "DP" & dpCounter.ToString, RadGrid1) dpCounter += 1 Next End If If mSubCodesAvailable Then Dim tableSubCode As New GridTableView(RadGrid1) tableSubCode.Name = "SubCodes" tableSubCode.DataKeyNames = New String() {"SubCodeID", "Day"} tableSubCode.Width = Unit.Percentage(100) columnSubCodeCreation("SubCode", "Sub_Code", tableSubCode) columnSubCodeCreation("Household", "HouseHold_Count", tableSubCode) If mstrClientDataCategoryID1Description.Trim <> "" Then columnSubCodeCreation(mstrClientDataCategoryID1Description.Trim, "CD1", tableSubCode) End If If mstrClientDataCategoryID2Description.Trim <> "" Then columnSubCodeCreation(mstrClientDataCategoryID2Description.Trim, "CD2", tableSubCode) End If If mstrClientDataCategoryID3Description.Trim <> "" Then columnSubCodeCreation(mstrClientDataCategoryID3Description.Trim, "CD3", tableSubCode) End If If mstrReportDemographicID1Description.Trim <> "" Then columnSubCodeCreation(mstrReportDemographicID1Description.Trim, "Demographic1", tableSubCode) End If If mstrReportDemographicID2Description.Trim <> "" Then columnSubCodeCreation(mstrReportDemographicID2Description.Trim, "Demographic2", tableSubCode) End If If mstrReportDemographicID3Description.Trim <> "" Then columnSubCodeCreation(mstrReportDemographicID3Description.Trim, "Demographic3", tableSubCode) End If If mstrReportDemographicID4Description.Trim <> "" Then columnSubCodeCreation(mstrReportDemographicID4Description.Trim, "Demographic4", tableSubCode) End If If mstrReportDemographicID5Description.Trim <> "" Then columnSubCodeCreation(mstrReportDemographicID5Description.Trim, "Demographic5", tableSubCode) End If columnSubCodeCreation("Selected", "Selected", tableSubCode) If UcHeader.objSession.ApplicationId <> CInt(ConfigurationManager.AppSettings("MediaviewerAppID")) Then columnSubCodeCreation("Forced", "Forced", tableSubCode) End If columnSubCodeCreation("Circ", "Circ", tableSubCode) columnSubCodeCreation("Coverage", "Coverage", tableSubCode) If UcHeader.objSession.ApplicationId <> CInt(ConfigurationManager.AppSettings("MediaviewerAppID")) Then Dim dpCounter As Integer = 1 Dim dpCollection As IList(Of RadListBoxItem) = rlbDistributionPatterns.CheckedItems For Each item As RadListBoxItem In dpCollection columnSubCodeCreation(item.Text, "DP" & dpCounter.ToString, tableSubCode) dpCounter += 1 Next End If End If Me.PlaceHolder1.Controls.Add(RadGrid1) End Sub Protected Sub RadGrid1_NeedDataSource(ByVal source As Object, ByVal e As GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource If mintCircSetID > 0 Then Dim intIndex As Integer = 0 Dim strSortedColumn As String = "" Dim strSortClause As String = "" mstrSQL = "" mstrSQL = "EXEC WB_sp_RetrieveGeographySelection_ForTelerik '" & mstrSessionID & "'," & mintEventID If mblnFullRunUtilizedInd Or cbSingleZip.Checked Then mstrSQL = mstrSQL & ",0" Else mstrSQL = mstrSQL & ",1" End If If cbSundayFR.Checked Or cbSundayHD.Checked Or cbSundaySC.Checked Or cbSundayMX.Checked Then mstrSQL = mstrSQL & ",1" Else mstrSQL = mstrSQL & ",0" End If If cbMondayFR.Checked Or cbMondayHD.Checked Or cbMondaySC.Checked Or cbMondayMX.Checked Then mstrSQL = mstrSQL & ",1" Else mstrSQL = mstrSQL & ",0" End If If cbTuesdayFR.Checked Or cbTuesdayHD.Checked Or cbTuesdaySC.Checked Or cbTuesdayMX.Checked Then mstrSQL = mstrSQL & ",1" Else mstrSQL = mstrSQL & ",0" End If If cbWednesdayFR.Checked Or cbWednesdayHD.Checked Or cbWednesdaySC.Checked Or cbWednesdayMX.Checked Then mstrSQL = mstrSQL & ",1" Else mstrSQL = mstrSQL & ",0" End If If cbThursdayFR.Checked Or cbThursdayHD.Checked Or cbThursdaySC.Checked Or cbThursdayMX.Checked Then mstrSQL = mstrSQL & ",1" Else mstrSQL = mstrSQL & ",0" End If If cbFridayFR.Checked Or cbFridayHD.Checked Or cbFridaySC.Checked Or cbFridayMX.Checked Then mstrSQL = mstrSQL & ",1" Else mstrSQL = mstrSQL & ",0" End If If cbSaturdayFR.Checked Or cbSaturdayHD.Checked Or cbSaturdaySC.Checked Or cbSaturdayMX.Checked Then mstrSQL = mstrSQL & ",1" Else mstrSQL = mstrSQL & ",0" End If mstrSQL = mstrSQL & "," & mintParentMap If cbSundayFR.Checked Or cbMondayFR.Checked Or cbTuesdayFR.Checked Or cbWednesdayFR.Checked Or cbThursdayFR.Checked Or cbFridayFR.Checked Or cbSaturdayFR.Checked Then mstrSQL = mstrSQL & ",1,1,1" Else If cbSundayHD.Checked Or cbMondayHD.Checked Or cbTuesdayHD.Checked Or cbWednesdayHD.Checked Or cbThursdayHD.Checked Or cbFridayHD.Checked Or cbSaturdayHD.Checked Then mstrSQL = mstrSQL & ",1" Else mstrSQL = mstrSQL & ",0" End If If cbSundayMX.Checked Or cbMondayMX.Checked Or cbTuesdayMX.Checked Or cbWednesdayMX.Checked Or cbThursdayMX.Checked Or cbFridayMX.Checked Or cbSaturdayMX.Checked Then mstrSQL = mstrSQL & ",1" Else mstrSQL = mstrSQL & ",0" End If If cbSundaySC.Checked Or cbMondaySC.Checked Or cbTuesdaySC.Checked Or cbWednesdaySC.Checked Or cbThursdaySC.Checked Or cbFridaySC.Checked Or cbSaturdaySC.Checked Then mstrSQL = mstrSQL & ",1" Else mstrSQL = mstrSQL & ",0" End If End If intIndex = UBound(Split(hidSortInformation.Value, ",")) Do While intIndex >= 0 strSortedColumn = Trim(Split(hidSortInformation.Value, ",")(intIndex)) strSortClause = strSortClause & strSortedColumn & "," intIndex -= 1 Loop strSortClause = Left(strSortClause, Len(strSortClause) - 1) mstrSQL = mstrSQL & ",'" & strSortClause & "'," If cbSortingByParent.Checked Then mstrSQL = mstrSQL & "1" Else mstrSQL = mstrSQL & "0" End If mstrSQL = mstrSQL & ",''" If Not e.IsFromDetailTable Then RadGrid1.DataSource = GetDataTable(mstrSQL & ",0,0,''") End If End If End Sub Private Sub RadGrid1_DetailTableDataBind(sender As Object, e As Telerik.Web.UI.GridDetailTableDataBindEventArgs) Handles RadGrid1.DetailTableDataBind Dim dataItem As GridDataItem = CType(e.DetailTableView.ParentItem, GridDataItem) Select Case e.DetailTableView.Name Case "SubCodes" Dim detailID As Integer = dataItem.GetDataKeyValue("DetailID").ToString() Dim Day As String = dataItem.GetDataKeyValue("Day").ToString() If mintCircSetID > 0 Then e.DetailTableView.DataSource = GetDataTable(mstrSQL & ",1," & detailID & ",'" & Day & "'") End If End Select End Sub Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim grid As RadGrid = CType(PlaceHolder1.FindControl("RadGrid1"), RadGrid) RadAjaxManager1.AjaxSettings.AddAjaxSetting(grid, grid) End Sub