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
Hi Philip,
If you want to get the new values in the row form the RowUpdating event you have to use e.values instead of e.Row.DataItem.
In you sample you have to change e.Row.DataItem("NewLevelCode") to e.Value("NewLevelCode") if you want to get the new entered values.
Here is a sample with events:
https://www.infragistics.com/samples/aspnet/data-grid/editing-rows-server-events
Hi Nadia,
e.values comes back as the original values for the columns I am editing too. Is there a property somewhere I need to change to make the values come through?
I am dynamically populating the grid in vb after load, so any settings will likely be default. the columnSetting is set to readonly="false" and an editor is set by editorid="WebDataGrid1_NumericEditorProvider1"
Here is the code I use to populate the grid
Private Sub Forecast_LoadComplete(sender As Object, e As EventArgs) Handles Me.LoadComplete Dim vDataView As System.Data.DataView = DirectCast(Grid.Select(DataSourceSelectArguments.Empty), System.Data.DataView) Dim field As Infragistics.Web.UI.GridControls.BoundDataField Dim mHeader As String = "" Dim mHeaderList = New List(Of String) Dim sHeader As String Dim gGroupField = New GroupField Dim settingColumn As EditingColumnSetting Dim sKey As String Dim lDataFieldList = New List(Of Infragistics.Web.UI.GridControls.BoundDataField) Dim lGroupFieldList = New List(Of Infragistics.Web.UI.GridControls.GroupField) If vDataView IsNot Nothing Then 'Get lists of all columns in webdatagrid For Each col In WebDataGrid1.Columns If col.GetType.ToString = "Infragistics.Web.UI.GridControls.BoundDataField" Then lDataFieldList.Add(col) End If If col.GetType.ToString = "Infragistics.Web.UI.GridControls.GroupField" Then lGroupFieldList.Add(col) End If Next 'Remove all columns from webdatagrid - can't be done inside webdatagrid1.columns loop For Each c In lDataFieldList WebDataGrid1.Columns.Remove(c) Next For Each c In lGroupFieldList WebDataGrid1.Columns.Remove(c) Next 'loop through columns in dataview For Each col In vDataView.Table.Columns 'create string to use as key for columns sKey = col.ToString field = New Infragistics.Web.UI.GridControls.BoundDataField field.Key = sKey field.DataFieldName = col.ToString 'columns are split in to groups by the name of the column "groupname_columnname" 'if a group doesn't exist then create one If InStr(col.ToString, "_") > 1 Then sHeader = Right(col.ToString, Len(col.ToString) - InStr(col.ToString, "_")) mHeader = Left(col.ToString, InStr(col.ToString, "_") - 1) If Not mHeaderList.Contains(mHeader) And mHeader.Length Then mHeaderList.Add(mHeader) gGroupField = New GroupField gGroupField.Key = mHeader gGroupField.Header.Text = mHeader WebDataGrid1.Columns.Add(gGroupField) End If gGroupField.Columns.Add(field) Else sHeader = col.ToString 'if there is no group in the column heading then just add it to the grid WebDataGrid1.Columns.Add(field) End If field.Header.Text = sHeader settingColumn = New EditingColumnSetting settingColumn.ColumnKey = sKey If InStr(sHeader, "Forecast") > 0 Then settingColumn.ReadOnly = False settingColumn.EditorID = "WebDataGrid1_NumericEditorProvider1" Else settingColumn.ReadOnly = True End If WebDataGrid1.Behaviors.EditingCore.Behaviors.CellEditing.ColumnSettings.Add(settingColumn) Next End If Dim vDataView2 As System.Data.DataView = DirectCast(Header.Select(DataSourceSelectArguments.Empty), System.Data.DataView) CommentVsActual.Value = vDataView2.Table.Rows(0)("CommentVsActual").ToString CommentVsForecast.Value = vDataView2.Table.Rows(0)("CommentVsForecast").ToString CommentStaff.Value = vDataView2.Table.Rows(0)("CommentStaff").ToString CommentOther.Value = vDataView2.Table.Rows(0)("CommentOther").ToString Status.SelectedValue = vDataView2.Table.Rows(0)("StatusCode").ToString Staff.Value = vDataView2.Table.Rows(0)("Staff") End Sub
Can you send me a small sample with the current scenario.
Is all the values are not correct or only this with the editor provider? As I see from the code that you shared you remove and add new columns on every page load. if you want to clear all the columns you can use WebDataGrid1.Columns.Clear().
can you try to recreate the columns in the page Load, not in the page LoadComplete