Hello, I have a little problem in a pretty straight forward scenario:
A WebHierarchicalDataGrid is filled with data from a DataSet on every PageLoad event with the following settings
- DataViewState is disable
- ViewState enabled (inherit)
- AutoCrud disabled
- BatchUpdate enabled
- DataSourceId is not set
Like I said, in the end of PageLoad, my BindGrid method is called
Protected Sub BindGrid()
Dim ds As DataSet = New DataSet
ds.Tables.Add(GetData(ddlEmployee.SelectedValue))
WebHierarchicalDataGrid1.DataSource = ds
WebHierarchicalDataGrid1.DataBind()
End Sub
Now, when update data in the grid, I manually update the database inside the RowUpdating event by calling a stored procedure.
The problem is - after all the rows have been updated and the page reloads, I still get the old values. Only if I refresh the page again, then I see the new values. So it seems to me, that when pressing the save button, the PageLoad is called, loading the still not updated, old values from the database to the grid, then the rows are updated in the database, but the grid shows the data that was load before the update.
What can I do. I cannot find a event that is called after all the rows have been updated so that I could rebind the grid to the updated datasource. Also, setting the DataViewState does not work, because it tells me that the datasource has no primary key. I would prefer a way without DataViewState though.
Thanks a lot, Kevin
Hello Kevin,
Thank you for posting in Infragistics forum.
It sounds like you have followed the correct steps to use Manual CRUD operations and Batch Updating feature with WHDG:
1) Enable Batch Updating
2) Set Auto CRUD to false
3) Handle the server side RowUpdating event ( or the other evens related to CRUD operations)
Could you please clarify what is the EnableAJAX property of the WHDG set to and if you data bind the grid in the RowUpdating event. I suggest setting the EnableAJAX property to false and call the DataBind() method in the RowUpdating event. Please let me know if this helps.
You can find more useful info on implementing Manual CRUD operations and Batch Updating on the following links:
http://es.infragistics.com/community/blogs/radoslav_minchev/archive/2010/12/18/manual-crud-webhierarchicaldatagrid.aspx
http://es.infragistics.com/samples/aspnet/data-grid/batch-updating-events
http://es.infragistics.com/samples/aspnet/hierarchical-data-grid/batch-updating
I will ask you to provide a feedback if the suggested helped you resolve your issue. If not please provide your code with your WHDG configuration and the code you execute in the RowUpdating event. I will be happy to assist you further.
Hi Hristo, thanks for your help. Unfortunately, setting enableAjax to false and calling DataBind() in the rowUpdating event didn't resolve the problem.
Protected Sub WebHierarchicalDataGrid1_RowUpdating(sender As Object, e As Infragistics.Web.UI.GridControls.RowUpdatingEventArgs) Handles WebHierarchicalDataGrid1.RowUpdating
For i As Integer = 0 To e.OldValues.Count - 1
Dim key As String = e.OldValues.Keys(i)
Dim oldValue As String = e.OldValues.Values(i)
Dim newValue As String = e.Values(key)
If (oldValue <> newValue) Then
Dim period As String = e.Row.Items.FindItemByKey(key).Column.Header.Text
Dim decimalValue As Nullable(Of Decimal)
If newValue = 0 Then
decimalValue = Nothing
Else
decimalValue = newValue
End If
employeeTableAdapter.UpdateValues(e.Row.Items(0).Value, e.Row.Items(1).Value, e.Row.Items(3).Value, CUInt(period), decimalValue)
Next
And here the code of my WebHierarchicalDataGrid:
<ig:WebHierarchicalDataGrid ID="WebHierarchicalDataGrid1" runat="server" AutoGenerateColumns="False" StyleSetName="Office2010Blue" Width="1160px" Height="500px" ItemCssClass="borderClass" EnableAjax="False"> <GroupingSettings EnableColumnGrouping="True">GroupingSettings> <Columns>
<ig:BoundDataField DataFieldName="MA_ID" Hidden="True" Key="MA_ID" Width="60px"> <Header Text="MA_ID"> Header> ig:BoundDataField>
// tons of column definitions...
Columns> <Behaviors> <ig:EditingCore AutoCRUD="False" BatchUpdating="True"> <Behaviors>
<ig:CellEditing><CellEditingClientEvents EnteringEditMode="WebDataGrid1_CellEditing_EnteringEditMode" ExitedEditMode="WebDataGrid1_CellEditing_ExitedEditMode" />
<ColumnSettings> <ig:EditingColumnSetting ColumnKey="MA_ID" ReadOnly="true" /> <ig:EditingColumnSetting ColumnKey="KeyDescription" ReadOnly="true" /> ColumnSettings> ig:CellEditing>
Behaviors>
ig:EditingCore>
<ig:Sorting> ig:Sorting>
<ig:ColumnMoving> ig:ColumnMoving>
<ig:ColumnResizing> ig:ColumnResizing>
ig:WebHierarchicalDataGrid>
I'm only using the WebHierarchicalDataGrid instead of a WebDataGrid because of it's Excel style columnGrouping feature.
thanks a lot for your help
Kevin
Hello Hristo
I tried to create a working example showing the issue. Like I said, I don't believe it's a problem/bug, I must be doing something wrong. Probably I'm using wrong events or forget something.
As for the example, please note that it is much simplified and is using an IList as a fake-kind of repository and as a replacement for a DataBase. In reality, I use an SQL Database and typed DataSets / TableAdapters to fill the DataSet that is bound to the grid, but it is easier this way than sending you a dump of my SQL database - the problem still appears. Please notice that only the Salary is updated in this example. Just Change one of the employees salary to any value, press save and see how the Grid is not updated, until you manually do it pressing F5.
To remind you shortly of my issue/scenario:
WHDG <-- local dataset as a datasource=<-- tableadapter <-- SQL DB
In the RowEditing event, I'm directly updating the SQL Database (or in the example project, the List), but after the PostBack is finished and the page is displayed, the grid is still showing the old values, until I reload (F5) the page again.
I hope you can help me. Thanks a lot, Kevin
It turned out to be a simple issue. Clearing the data source in the RowUpdating event before binding seems to fix this behavior:
WebHierarchicalDataGrid1.GridView.ClearDataSource();
BindGrid();
Please let me know if this works on your machine, it does on mine.
Hi Hristo
Thank you very much - your fix did resolve the problem!
I have one question though: As the rowUpdating event is called for every row that is being updated - wont the grid be bound to the datasource n times for n-rows?
It's not a big deal, I'm just curious and noticed that it becomes a bit slower with every row that I edit.
Thanks again!
Yes, the RowUpdating event is called for every row being updated and the grid will be bound n times for n rows. However this should not be an issue as long as BatchUpdating is enabled because you can edit as many rows as you can and the RowUpdating will not be fired until a postback is triggered. It is possible to experience issues with the performance speed on the postback if many rows are being updated, but not before that.
Still if you enable DataViewState then it will not be necessary to call DataBind() in your BindGrid() method. This should prevent you from any issues with the performance when making a postback that triggers the RowUpdating. If you set EnableDataViewState to true then you will need to set a primary key for the data table as follows:
DataColumn[] PrimaryKeyColumns = new DataColumn[1];
PrimaryKeyColumns[0] = dt.Columns["ID"];
dt.PrimaryKey = PrimaryKeyColumns;
You can refer for more info at http://help.infragistics.com/Help/Doc/ASPNET/2014.1/CLR4.0/html/WebDataGrid_Getting_Started_with_WebDataGrid_EnableDataViewState_Property.html
I hope it will be helpful for you - sometimes handling the DataViewState property is tricky.
Please let me know if you have any further questions, I will be glad to help.
If you have any further questions regarding the matter, just let me know. I will be glad to help.