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
If you have any further questions regarding the matter, just let me know. I will be glad to help.
Hello Kevin,
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.
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!
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.
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