I am building my radgrid dynamically from the Page_Init of my form. The PageInit calls the procedure defineGridStructure. Below is the code for that prodedure. Near the top of the procedure you will see me call WB_sp_RetrieveGeographySelectionColumnOrder store procedure. This gets me the columns in the order the user wants to see them. In the Do While loop, I create the columns in the order the user wants them and with the attributes needed. (columnCreation is the procedure that does this). This RadGrid gets its information using the NeedDataSource and ItemDataBound functions for the Grid. When the screen populates the grid works great, column order is what the user wants, and data is retrieved.
Here is the problem: While the user is on the form, they can pop-up another form which allows them to set the columns in different order. Once they save that, they can then come back to the original form, click a submit button and the screen should refresh with the new order of columns. Stepping through the code, my defineGridStructure runs fine, calls the Stored Procedure to get the new column order and applies the new order. It then goes to the NeedDataSource and ItemDataBound respectively. Inside the ItemDataBound is where the issue lies. Once I get my e.Item (GridDataItem) dataRow, I see the the information is still being bound to the columns in the original order. I get errors because of the different type issue.
example: in the original order, the first column was gridtemplatecolumn for checkbox, and second was a string. Once I switched the two in the pop-up, and hit the submit, the first column is a GridBoundColumn for string, the second column is gridtemplatecolumn for checkbox but the information bound to the row is still looking at it like the original order.
It seems to be something about after changing the order of columns, I need to leave the screen totally, come back in (the system will run the same code) but this time the binding of data is correct. It errors when I have the grid up already, make some changes in order of columns in my database table, then re-submit the page to pick up the new changes. Maybe a session thing. What do I need to do?
defineGridStructure procedure
Here is the problem: While the user is on the form, they can pop-up another form which allows them to set the columns in different order. Once they save that, they can then come back to the original form, click a submit button and the screen should refresh with the new order of columns. Stepping through the code, my defineGridStructure runs fine, calls the Stored Procedure to get the new column order and applies the new order. It then goes to the NeedDataSource and ItemDataBound respectively. Inside the ItemDataBound is where the issue lies. Once I get my e.Item (GridDataItem) dataRow, I see the the information is still being bound to the columns in the original order. I get errors because of the different type issue.
example: in the original order, the first column was gridtemplatecolumn for checkbox, and second was a string. Once I switched the two in the pop-up, and hit the submit, the first column is a GridBoundColumn for string, the second column is gridtemplatecolumn for checkbox but the information bound to the row is still looking at it like the original order.
It seems to be something about after changing the order of columns, I need to leave the screen totally, come back in (the system will run the same code) but this time the binding of data is correct. It errors when I have the grid up already, make some changes in order of columns in my database table, then re-submit the page to pick up the new changes. Maybe a session thing. What do I need to do?
defineGridStructure procedure
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.MasterTableView.NoDetailRecordsText = "No records could be found."
RadGrid1.MasterTableView.NoMasterRecordsText = "No records could be found."
RadGrid1.MasterTableView.ShowHeadersWhenNoRecords = True
RadGrid1.Skin = "WebBlue"
RadGrid1.HeaderStyle.CssClass = "RadGridHeader"
RadGrid1.MasterTableView.ItemStyle.CssClass = "DetailsRow1"
RadGrid1.MasterTableView.AlternatingItemStyle.CssClass = "DetailsRow2"
RadGrid1.GroupingSettings.CaseSensitive = False
RadGrid1.ClientSettings.ClientEvents.OnGridCreated = "GetGridObject"
RadGrid1.ClientSettings.Scrolling.FrozenColumnsCount = 2
RadGrid1.ClientSettings.AllowColumnsReorder = True
RadGrid1.ClientSettings.ColumnsReorderMethod = GridClientSettings.GridColumnsReorderMethod.Reorder
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.ClientSettings.ClientEvents.OnFilterMenuShowing = "filterMenuShowing"
RadGrid1.FilterMenu.OnClientShowing = "MenuShowing"
If ConfigurationManager.AppSettings("geoSelectionGridSize") <> "" Then
RadGrid1.MasterTableView.PageSize = ConfigurationManager.AppSettings("geoSelectionGridSize")
Else
RadGrid1.MasterTableView.PageSize = 50
End If
RadGrid1.MasterTableView.AllowMultiColumnSorting = True
RadGrid1.MasterTableView.DataKeyNames = New String() {"DetailID", "Day", "FoundGeographies", "SubZipCount"}
RadGrid1.MasterTableView.HierarchyLoadMode = GridChildLoadMode.ServerBind
RadGrid1.MasterTableView.HierarchyDefaultExpanded = True
Dim dpCounter As Integer = 1
Dim dpCollection As IList(Of RadListBoxItem) = rlbDistributionPatterns.CheckedItems
For Each item As RadListBoxItem In dpCollection
Dim columnGroup As New GridColumnGroup
columnGroup.HeaderText = item.Text
columnGroup.Name = "GroupDP" & dpCounter.ToString
columnGroup.HeaderStyle.HorizontalAlign = HorizontalAlign.Center
RadGrid1.MasterTableView.ColumnGroups.Add(columnGroup)
dpCounter += 1
Next
Dim strSQL As String
Dim columnHeader As String = ""
Dim columnName As String = ""
Try
strSQL = "EXEC WB_sp_RetrieveGeographySelectionColumnOrder " & UcHeader.UserId
mobjSqlDataReaderColumnheaders = mobjDatabase.fnRetrieveData("DATAREADER", strSQL, "Columns")
Do While mobjSqlDataReaderColumnheaders.Read
columnHeader = mobjSqlDataReaderColumnheaders("ColumnHeader").ToString.Trim
columnName = mobjSqlDataReaderColumnheaders("ColumnName").ToString.Trim
If (columnName = "LocationMarket" Or columnName = "LocationNumber" Or columnName = "LocationName" Or columnName = "Distance" Or _
columnName = "Sales" Or columnName = "TotalSales" Or columnName = "BOS" Or columnName = "CumeBOS" Or columnName = "SPH" Or columnName = "SPHIndex") Then
If miZipCodeStoreAssociationTypeID > 0 Then
columnCreation(columnHeader, columnName, RadGrid1)
End If
ElseIf Left(columnName, 2) = "CD" Then
If Right(columnName, 1) = 1 And mstrClientDataCategoryID1Description.Trim <> "" Then
columnCreation(mstrClientDataCategoryID1Description.Trim, "CD1", RadGrid1)
End If
If Right(columnName, 1) = 2 And mstrClientDataCategoryID2Description.Trim <> "" Then
columnCreation(mstrClientDataCategoryID2Description.Trim, "CD2", RadGrid1)
End If
If Right(columnName, 1) = 3 And mstrClientDataCategoryID3Description.Trim <> "" Then
columnCreation(mstrClientDataCategoryID3Description.Trim, "CD3", RadGrid1)
End If
ElseIf Left(columnName, 11) = "Demographic" Then
If Right(columnName, 1) = 1 And mstrReportDemographicID1Description.Trim <> "" Then
columnCreation(mstrReportDemographicID1Description.Trim, "Demographic1", RadGrid1)
End If
If Right(columnName, 1) = 2 And mstrReportDemographicID2Description.Trim <> "" Then
columnCreation(mstrReportDemographicID2Description.Trim, "Demographic2", RadGrid1)
End If
If Right(columnName, 1) = 3 And mstrReportDemographicID3Description.Trim <> "" Then
columnCreation(mstrReportDemographicID3Description.Trim, "Demographic3", RadGrid1)
End If
If Right(columnName, 1) = 4 And mstrReportDemographicID4Description.Trim <> "" Then
columnCreation(mstrReportDemographicID4Description.Trim, "Demographic4", RadGrid1)
End If
If Right(columnName, 1) = 5 And mstrReportDemographicID5Description.Trim <> "" Then
columnCreation(mstrReportDemographicID5Description.Trim, "Demographic5", RadGrid1)
End If
ElseIf (columnName = "Forced" Or columnName = "Version" Or columnName = "SubVersionCategory" Or columnName = "DeliveryCode" Or columnName = "DistributionPatterns") Then
If UcHeader.objSession.ApplicationId <> CInt(ConfigurationManager.AppSettings("MediaviewerAppID")) Then
If columnName = "Forced" Then
columnCreation(columnHeader, columnName, RadGrid1)
End If
If columnName = "Version" And miVersionsCategoryID > 0 Then
columnCreation(columnHeader, columnName, RadGrid1)
End If
If columnName = "SubVersionCategory" And miVersionsCategoryID > 0 Then
columnCreation(columnHeader, columnName, RadGrid1)
End If
If columnName = "DeliveryCode" And miDeliveryCodeCount > 0 Then
columnCreation(columnHeader, columnName, RadGrid1)
End If
If columnName = "DistributionPatterns" Then
dpCounter = 1
For Each item As RadListBoxItem In dpCollection
columnCreation(item.Text, "DP" & dpCounter.ToString, RadGrid1)
columnCreation(item.Text, "CoverageDP" & dpCounter.ToString, RadGrid1)
dpCounter += 1
Next
End If
End If
Else
columnCreation(columnHeader, columnName, RadGrid1)
End If
Loop
mobjSqlDataReaderColumnheaders.Close()
mobjSqlDataReaderColumnheaders = Nothing
Catch exp As Exception
Throw New Exception(exp.Message & ", frmGeographySelection.defineGridStructure")
End Try
columnCreation("Geography", "Geography2", RadGrid1)
columnCreation("Circ Type", "CirculationTypeDescription2", RadGrid1)
columnCreation("FoundGeographies", "FoundGeographies", RadGrid1)
RadGrid1.Width = Unit.Pixel(widthOfRadGridDetails + 40)
Me.PlaceHolder1.Controls.Add(RadGrid1)