Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
15
Can't get new value from webdatagrid in server side code
posted

HI,

I've spent quite a lot of time trying to solve this problem, and have not been able to solve it.

I have a webdatagrid which I populate on page_loadcomplete from a dynamic sql procedure. This works fine. 

I am then trying to use the webdatagrid rowupdating event (which triggers before refreshing the webdatagrid) to get the values in the cells which i've updated, use these values to create a sql update string, make that string the updatecommand for the datasource, and then update the webdatagrid.

The problem is that the values I'm getting from the webdatagrid in the rowupdating event are the values which were originally in the grid and not the new ones which I have entered. Apart from that the update command seems to work fine.

Here is my WebDataGrid:

        <ig:WebDataGrid ID="WebDataGrid1" runat="server" Height="350px" Width="100%" DataSourceID="Grid" AutoGenerateColumns="False">
            <EditorProviders>
                <ig:NumericEditorProvider ID="WebDataGrid1_NumericEditorProvider1">
                    <EditorControl runat="server" ClientIDMode="Predictable"></EditorControl>
                </ig:NumericEditorProvider>
            </EditorProviders>
            <Behaviors>
                <ig:EditingCore AutoCRUD="False">
                    <Behaviors>
                        <ig:CellEditing></ig:CellEditing>
                    </Behaviors>
                </ig:EditingCore>
            </Behaviors>
        </ig:WebDataGrid>

Here is my rowupdating event (grid is the name of the sqldatasource):

    Private Sub WebDataGrid1_RowUpdating(sender As Object, e As RowUpdatingEventArgs) Handles WebDataGrid1.RowUpdating

        Dim sMonth As String
        Dim iMonth As Integer
        Dim sUpdate As String
        sUpdate = "UPDATE dbo.vForecast SET "

        Dim co As Infragistics.Web.UI.GridControls.GroupField
        Dim c As BoundDataField

        Dim i As Integer
        i = 0

        For Each col In WebDataGrid1.Columns
            If col.GetType.ToString = "Infragistics.Web.UI.GridControls.GroupField" Then
                co = col
                For Each c In co.Columns
                    If InStr(co.Key.ToString(), "Forecast/Actual") > 0 And InStr(c.Key.ToString(), "Forecast") > 0 Then
                        sMonth = Right(c.Key.ToString, c.Key.ToString.Length - InStr(c.Key.ToString, "Forecast") - 7)
                        iMonth = DateTime.ParseExact(sMonth, "MMMM", System.Globalization.CultureInfo.CurrentCulture).Month
                        sUpdate += "P" + iMonth.ToString + "=" + e.Row.Items(i).Text.ToString + ", "
                    End If
                    i = i + 1
                Next
            Else
                i = i + 1
            End If
        Next

        sUpdate = Left(sUpdate, Len(sUpdate) - 2)
        sUpdate += " WHERE NewLevelCode='" + e.Row.DataItem("NewLevelCode").ToString + "' AND FiscalYear=@FiscalYear AND ForecastPeriod=@ForecastPeriod"
        Grid.UpdateCommand = sUpdate
        Grid.UpdateCommandType = SqlDataSourceCommandType.Text

        Grid.Update()
    End Sub