Using the various examples of doing inplace editing/updating, I'm running into issues. I have a radgrid that autogenerates the columns depending upon a question the user selects. The page unto itself works fine. The grid gets populated correctly and the inplace editing columns come up just fine. Just nothing updates when I click the "update" button........
FYI - all columns are numeric double values.
The issue I've seen is that at the "For Each Column In e.Item.OwnerTableView.Columns" loop in the update subroutine, it does not cycle, catch, identify, know that, etc. there are columns in the grid. I can have 44 autogenerated columns and this For/Next loop only executes once and then moves on.
Any and all suggestions are more than welcome!
Here is the code on my aspx page:
In my code behind I have this as my grid source:
My "getDatabaseColumns" routing (called above) populates the query depending upon the question the user has selected:
This is my 'needDataSource':
This is my update routine:
And finally, my 'processEdits' routine:
FYI - all columns are numeric double values.
The issue I've seen is that at the "For Each Column In e.Item.OwnerTableView.Columns" loop in the update subroutine, it does not cycle, catch, identify, know that, etc. there are columns in the grid. I can have 44 autogenerated columns and this For/Next loop only executes once and then moves on.
Any and all suggestions are more than welcome!
Here is the code on my aspx page:
<telerik:RadGrid ID="rg_GrowthRates" runat="server" AllowSorting="True" CellSpacing="0" GridLines="None" AllowFilteringByColumn="True" Width="100%" AllowPaging="True" PageSize="15" EnableViewState="False" ViewStateMode="Disabled" Skin="Metro" AllowAutomaticUpdates="True" AutoGenerateEditColumn="True"> <MasterTableView DataKeyNames="ID_SurveyInstitutional" EditMode="InPlace" > <CommandItemSettings ShowAddNewRecordButton="False" /> <EditFormSettings> <EditColumn FilterControlAltText="Filter EditCommandColumn1 column" UniqueName="EditCommandColumn1"> </EditColumn> </EditFormSettings> <EditItemStyle BackColor="LightSteelBlue" BorderColor="Black" BorderStyle="Dashed" BorderWidth="1px" HorizontalAlign="Center" VerticalAlign="Middle" Width="50px" /> <PagerStyle AlwaysVisible="True" PageSizes="15;30;45;60;All" /> <CommandItemStyle BackColor="#FFFFC0" /> </MasterTableView> <PagerStyle AlwaysVisible="True" PageButtonCount="15" PageSizes="15;30;45;60;All" /></telerik:RadGrid>In my code behind I have this as my grid source:
Private ReadOnly Property GridSource As DataTable Get Dim obj As Object = Me.ViewState("_gds") If (Not obj Is Nothing) Then Return CType(obj, DataTable) Else querystring = "SELECT ID_SurveyInstitutional, " & getDatabaseColumns(Session("selectedQuestion")) & " " & _ "FROM SurveyInstitutional " & _ "WHERE ID_AvailableQuarters = " & Session("selectedQuarter") RERCDataCenterConnection.Open() Dim existingCommand As New SqlCommand(querystring, RERCDataCenterConnection) Dim da As New SqlDataAdapter(existingCommand) Try da.Fill(questionTable) Catch ex As Exception Finally RERCDataCenterConnection.Close() End Try Me.ViewState("_gds") = questionTable Return questionTable End If End GetEnd PropertyMy "getDatabaseColumns" routing (called above) populates the query depending upon the question the user has selected:
Function getDatabaseColumns(ByVal whichQuestion As Integer) Dim columnList As New DataTable Dim columnString As String = "" querystring = "SELECT DatabaseColumn FROM Const_InstitutionalColumnMatrix WHERE ID_Const_EditableQuestions = " & whichQuestion RERCDataCenterConnection.Open() Using getColumns As New SqlCommand(querystring, RERCDataCenterConnection) Dim da As New SqlDataAdapter(getColumns) Try da.Fill(columnList) Catch ex As Exception Finally RERCDataCenterConnection.Close() End Try End Using For Each row As DataRow In columnList.Rows columnString = columnString & row("DatabaseColumn") & ", " Next columnString = Left(columnString, Len(columnString) - 2) Return columnStringEnd FunctionThis is my 'needDataSource':
Private Sub rg_GrowthRates_NeedDataSource(sender As Object, e As GridNeedDataSourceEventArgs) Handles rg_GrowthRates.NeedDataSource ' If they select "Select a Question from the dropdown then clear the grid If CInt(Session("selectedQuestion")) < 1 Then rg_GrowthRates.DataSource = New String() {} Exit Sub End If rg_GrowthRates.DataSource = Me.GridSourceEnd SubThis is my update routine:
Private Sub rg_GrowthRates_UpdateCommand(sender As Object, e As GridCommandEventArgs) Handles rg_GrowthRates.UpdateCommand Dim item As GridEditableItem = DirectCast(e.Item, GridEditableItem) Dim currentID As String = item.GetDataKeyValue("ID_SurveyInstitutional").ToString() Dim editedItem As GridEditableItem = CType(e.Item, GridEditableItem) Dim editMan As GridEditManager = editedItem.EditManager Dim column As GridColumn For Each column In e.Item.OwnerTableView.Columns If TypeOf column Is IGridEditableColumn Then Dim editableCol As IGridEditableColumn = CType(column, IGridEditableColumn) If (editableCol.IsEditable) Then Dim editor As IGridColumnEditor = editMan.GetColumnEditor(editableCol) Dim editorText As String = "" Dim editorValue As Object = Nothing If (TypeOf editor Is GridTextColumnEditor) Then editorText = CType(editor, GridTextColumnEditor).Text editorValue = CType(editor, GridTextColumnEditor).Text End If If (TypeOf editor Is GridBoolColumnEditor) Then editorText = CType(editor, GridBoolColumnEditor).Value.ToString() editorValue = CType(editor, GridBoolColumnEditor).Value End If If (TypeOf editor Is GridDropDownColumnEditor) Then editorText = CType(editor, GridDropDownColumnEditor).SelectedText + "; " + CType(editor, GridDropDownColumnEditor).SelectedValue editorValue = CType(editor, GridDropDownColumnEditor).SelectedValue End If Try Dim changedRows As DataRow() = Me.GridSource.Select("ID_SurveyInstitutional = " + editedItem.OwnerTableView.DataKeyValues(editedItem.ItemIndex)("ID_SurveyInstitutional").ToString()) changedRows(0)(column.UniqueName) = editorValue Me.GridSource.AcceptChanges() Catch ex As Exception e.Canceled = True End Try processEdits(column.UniqueName, editorValue, currentID) End If End If Next rg_GrowthRates.MasterTableView.ClearEditItems()End SubAnd finally, my 'processEdits' routine:
Protected Sub processEdits(ByVal columnName As String, ByVal newVal As String, ByVal currentID As Integer) Dim valueToUpdate As Double If Not IsDBNull(newVal) And Trim(newVal) <> "" Then valueToUpdate = CDbl(newVal) querystring = "UPDATE SurveyInstitutional " & _ "SET " & columnName & " = " & valueToUpdate & " " & _ "WHERE ID_SurveyInstitutional = " & CInt(currentID) Else RERCDataCenterConnection.Close() Exit Sub End If RERCDataCenterConnection.Open() Dim processEditAction As New SqlCommand(querystring, RERCDataCenterConnection) processEditAction.ExecuteNonQuery() RERCDataCenterConnection.Close() rg_GrowthRates.EditIndexes.Clear() rg_GrowthRates.Rebind()End Sub