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

Inplace Update Not Functioning

2 Answers 24 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Mike asked on 05 Sep 2013, 03:01 PM
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:

<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 Get
End Property

My "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 columnString
End Function

This 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.GridSource
 
End Sub

This 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 Sub

And 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

2 Answers, 1 is accepted

Sort by
0
Mike
Top achievements
Rank 1
answered on 06 Sep 2013, 06:25 PM
This line of code:

For Each column In e.Item.OwnerTableView.Columns
Needed to be changed to :
For Each column In e.Item.OwnerTableView.RenderColumns

As a suggestion to the Telerik support team, the first line of code was taken directly from your examples of how to update autogenerated columns in a radgrid.  Since we now know it does not work, how about updating the example code so that it's correct?  

I appreciate the quick response I received on this, but I did spend 4-5 hours trying to puzzle this out before posting this on the forum.
0
Angel Petrov
Telerik team
answered on 10 Sep 2013, 12:00 PM
Hi Mike,

Please accept our apologies for the inconvenience caused. We will update our online documentation as soon as possible.

Additionally thank you for sharing your findings with the community.

Regards,
Angel Petrov
Telerik
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 the blog feed now.
Tags
Grid
Asked by
Mike
Top achievements
Rank 1
Answers by
Mike
Top achievements
Rank 1
Angel Petrov
Telerik team
Share this question
or