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 screen with lots of controls and one list of items. This item list is shown in a WebGrid. I have two buttons to add and remove items into/from that list. When adding, another modal dialog pops up to select the correct item. When deleting, this is done by a checkbox column in the grid. And there's a save button on the form to save all data together back to the database. When a new row gets added to the WebGrid, this may not be saved to the database at that time, only later, if the user clicks on Save.
I had to make bigger changes of this existing (working) page, because of bad design. Actually I almost had to rewrite it.
In Page.Load I read in all data from the database (including the list of items) and store this in a local structure. I do not want to use session variables. Storing data in ViewState would be ok.
What is the correct way of implementing something like this? It seems to be a standard problem. Is there a demo for this available somewhere? Should I make the WebGrid somehow unbound?
In Page.Load I read in the data. And in grid.InitializeDataSource I set the e.DataSource to the values from what I read in Page.Load earlier (by creating a table and assigning it). On Postback, I cannot read in the data again, because this would overwrite the current data. So after a Postback, the internal variable doesn't contain any data anymore. When clicking on Save, I save all fields back to the database. Is this design correct so far?
But how would I implement the insert/delete of the rows to the WebGrid? For the Add button (<asp:Button>) I have an attribute like this: OnClientClick="ModalDialog(...
In the click handler on the server side I read the ID of the selected item from a session variable (still bad design, but unchanged), which was set in the selection dialog, then get some more info from the DB and I think then I should add this data as a row to the WebGrid. Is that correct? How would I add this row? In the Button click event adding a row to the grid.RootTable? And even if this would work, how should I afterwards refresh the grid?
Please help getting this designed correct with your control. We are using WebGrid version 6.0.7200.218. An example would be even better. But just help on the design is also ok. I think because this is a common problem, maybe there is already an example somewhere.
Thanks
Hi Glenn,
Thanks for your new sample.
We use the WebGrid version 6.0.7200.218 (as mentioned in initial question) and framework version 3.0.5000.705 (ActiveReports.Exporting.dll version 5.0.7200.3).
Yes, there are several problems with the sample, like that both Update buttons don't work, the crash, etc. but I can ignore all this, as long as this happens only in the sample and not in our real project. If you would still like to investigate, I'm happy to help. (I don't think it's related to this minor version difference.)
Ok, so with your sample I could add the row on the server side. I had to change a little bit, because casting to a DataSet didn't work. Here is what finally helped me (VB.NET):
Dim dt As DataTable = CType(grid.DataSource, DataTable) Dim values() As Object = {1, "init", "value", 0.0, 0.0} dt.Rows.Add(values) grid.RebindDataSource()
I'm not finished yet, but I assume there will be no other problems related to this. If there are, I will reply again or open a new thread (if not directly related).
Thanks,
Eric
Hello Glenn,
Thanks for your answer. BulkUpdate sounds like letting WebGrid do all the Update, but all at once. I looked through your sample and the BulkUpdate description, but I'm still missing something. Also, I'd like to mention the differences:
- The final Save to the database is done by me (server side) through a single call to a stored procedure (passing XML with all the grid data). In your sample you are somehow using a DataAdapter instead.
- I'm not sure what I'm missing, but when I click the button "Add Row" your sample crashes. The JavaScript GridAddRow runs successfully through, but then, within WebGrid code, somewhere it crashes. What happens is that a window pops up showing an unhandled exception (NullReferenceException in WebGrid.DataBinding). I can only click on Copy or Close.
- What's the exact purpose of the AddRow/UpdateRow handler setting e.ReturnValue=false?
- The main difference to what I need is that you add the data by the JavaScript GridAddRow. I have to add the data on the server side, because I need to get the data from the database first. I don't know how to add a row to the WebGrid on the server side without letting WebGrid go through a InitializeDataSouce call.
Any hints on this?
One more info on this: The old application worked - at least regarding the unbound data handling. I think it's a bad design, but decide yourself. If I cannot find a better solution quickly, I'll will use this also. Here it is:
In Page_Load the data for the grid is loaded from the database. The full DataSet is stored in a Session variable. Then calls to grid.ClearCachedDataSource() grid.DataSource=(from session), then grid.DataBind(). The event grid_InitializeDataSource is not implemented.
When clicking the Add button, the modal popup, opened by JavaScript in the OnClientClick event selects the data and stores the ID in another session variable. In the button handler event (server side) the DataSet from the session is being read. A new DataRow is added and again grid.ClearCachedDataSource, grid.DataSource=, grid.DataBind is set.
I think it is bad to store the full dataset in the session (and also the ID of the selection dialog). If not other possible, at least ViewState for the DataSet should be used. But I think this data belongs to the WebGrid, and I should not cache this data in my code again.
I have updated the sample so there is a button to add and update row in server side, the basic idea is still the same. Sample attached.
The database operation, for simplicity is using data adapter, since internally WebGrid will mark the updated, added, or deleted data row with the correct row state (Modified, Added, or deleted ), so calling the data adapter update method will process the modified, deleted, and added data based on the data adapter update, insert, or delete command.
In my sample, during AddRow and UpdateRow event handler I return false in order to prevent the WebGrid internal event handler to execute because we are not doing any database operation.
Regarding the error you mention during Add Row buton click, I have not encounter such issue in my environment, have you used the latest WebGrid 6 and WebUI Framework 3? The latest build is 219 and 752 respectively.
I can't comment on whether the design is bad or good. However, I have provide an alternative method if you willing to try.
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