iSeller Commerce
iSeller POS Retail
iSeller POS F&B
iSeller POS Express
Crosslight
WebUI
ClientUI
What's New
Download Trial
Web Solution
Mobile Solution
Enterprise Solution
Custom Development
Blog
Community
Latest Development Blogs
ForumPostTopic
Browse By Tag
Hi
I have a simple screen with some edit fields and a WebGrid. The data comes from the database and gets written to the database. Reading and writing is one single stored procedure call (the WebGrid should not do anything itself).
The grid contains a RowChecker column and a RadioButton column (ColumnType=Custom).
What happens right now:
1. Page_Init
2. Page_Load: If not postback load data from database
3. grid_InitializeDataSource: From the data data read previously a DataTable gets created and passed to the WebGrid by grid.DataSource=dt, grid.DataBind()
4. User changes some checkboxes in the grid and presses Save. A Postback starts.
5. Page_Init
6. Page_Load, but no reading from database, because postback
7. grid_InitializeDataSource: The grid is emptied, because no data around.
8. SaveButton_Click: Trying to read selected user selection from the grid, but grid is empty.
So as you can see, this doesn't work. I expected that the postback keeps the data in the grid (and not call InitializeDataSource again), so that I can read it in the SaveButton_Click. How should this work? Is there a sample around for this scenario?
If I change Page_Load or grid_InitializeDataSource to read in the database again, all user selections get lost. So that is not the way to go. Any ideas?
In initialize data source event, I suggest you to use a single of code as follow “e.DataSource = dt” rather than “grid.DataSource = dt, grid.DataBind()”.
In step #6 (after postback), no reading from database, seems causing the data is emptied in WebGrid on postback since there is no data table passed to WebGrid. You may check BindtoTraditionalDataSource.aspx reference sample in WebGridSamples project as sample.
If all user selections get lost after postback, please ensure that you’ve used “IsRowChecker” and set “RestoreRowSelection” property to either ‘RootTable’, or ‘All’. Please check PreserveCheckedRows.aspx reference sample in WebGridSamples project.
Click here for the link that shows the life cycle of WebGrid server side event during postback and flypostback. Please check the link for more detail information.
Hope this helps.
*a running simple sample that replicates the issue (plus the step-by-step to reproduce the issue) will be so much helpful to analyze the issue. If necessary, you can use any data source that available in WebGridSamples project.
Hi Yudi, Thanks for your answer and all the hints. Yes, the main problem was the call to grid.DataBind(). After removing this (and changing grid.DataSource to e.DataSource) the event InitializeDataSource was not been called anymore. So this problem is solved.
Hi Yudi, Thanks for your answer and all the hints.
Yes, the main problem was the call to grid.DataBind(). After removing this (and changing grid.DataSource to e.DataSource) the event InitializeDataSource was not been called anymore. So this problem is solved.
Glad to hear that part of the problem solved.
I couldn't find the sample PreserveCheckedRows you mentioned. By searching your support area, I found the link http://www.intersoftpt.com/Community/WebGrid/Retaining-Checkbox-with-Classic-Paging-Navigation/ and there was a sample you created. But unfortunately that download yields to a 404 page (not found). Where should I find your two samples? I found the sample BindtoTraditionalDataSource only (maybe modified) in another thread here, but not the original sample itself. Maybe I didn't install sample or so? Are they on your website somewhere? At least they are not found when clicking on search. This is something you could improve and would help a lot. Also, searching for "RestoreRowSelection" just finds some threads, but not the documentation. Is this documented somewhere?
I couldn't find the sample PreserveCheckedRows you mentioned. By searching your support area, I found the link http://www.intersoftpt.com/Community/WebGrid/Retaining-Checkbox-with-Classic-Paging-Navigation/ and there was a sample you created. But unfortunately that download yields to a 404 page (not found).
Where should I find your two samples? I found the sample BindtoTraditionalDataSource only (maybe modified) in another thread here, but not the original sample itself. Maybe I didn't install sample or so? Are they on your website somewhere? At least they are not found when clicking on search. This is something you could improve and would help a lot. Also, searching for "RestoreRowSelection" just finds some threads, but not the documentation. Is this documented somewhere?
The sample files (BindToTraditionalDataSource.aspx and PreserveCheckedRows.aspx) can be found in following location.
BindToTraditionalDataSource.aspx sample
Link to live sample: http://live.intersoftpt.com/cs/WebGrid/BindtoTraditionalDataSource.aspx.
Local sample: start > All Programs > Intersoft WebUI Studio 2009 R2 SP1 > WebUI Studio for ASP.NET > WebGrid 7 > C# Samples (Visual Studio 2008 Solution) or VB Samples (Visual Studio 2008 Solution). After the solution is loaded, on the ‘Solution Explorer’, find BindToTraditionalDataSource.aspx sample.
PreserveCheckedRows.aspx sample
Link to live sample: http://live.intersoftpt.com/cs/WebGrid/PreserveCheckedRows.aspx.
Local sample: start > All Programs > Intersoft WebUI Studio 2009 R2 SP1 > WebUI Studio for ASP.NET > WebGrid 7 > C# Samples (Visual Studio 2008 Solution) or VB Samples (Visual Studio 2008 Solution). After the solution is loaded, on the ‘Solution Explorer’, find PreserveCheckedRows.aspx sample.
IsRowChecker is set to true on one column, so that's ok. RestoreRowSelection is not used anywhere. Do I need this? How would I use it?
‘RestoreRowSelection’ is a feature that first introduced in the second 2008 release to automatically preserver/selected rows on both FullPostBack and FlyPostBack. With this feature, users can now preserve the previously checked rows while performing other actions such as moving to other pages, grouping, sorting, and filtering and so on. Furthermore, WebGrid will mark back the checked rows when it found the previously checked rows in the page. It will also restore the checked selection so that user can easily notice on checked rows.
The setting to enable this feature is controlled by RestoreRowSelection property inside the LayoutSettings property of WebGrid. this property has 4 possible values: Disabled – the default value, which turns off the row selection restoration; RootTableOnly – only checked rows in root table will be restored; ChildTableOnly – only checked rows in child table will be restored; All – all checked rows in any table types will be restored.
The page was actually fully working before, I just had to add a small extension. Because of the bad design, a have actually rewritten most of the backend code. There was no InitializeDataSource event implemented previously for example. This is also the reason why I had this .DataBind code in there - I just moved it from the Page.Load event into there.
I added RestoreRowSelection to LayoutSettings, but this didn't change anything. I believe this is only for preserving the selected rows, so I don't need that. I just need to preserve the checked rows and that's dont automatically I think.
But I still have the problem that my selections get away. I'll try to create a sample, although this might take a few hours.
Thanks, Eric
I started a new thread for the remaining problem:
http://www.intersoftpt.com/Community/WebGrid/Grid-Resets-after-PostBack/
or
Choose this if you're already a member of Intersoft Community Forum. You can link your OpenID account to your existing Intersoft Social ID.
Choose this if you don't have an Intersoft account yet. Your authenticated OpenID will be automatically linked to your new Intersoft account.
Enter your Wordpress Blogname