Unbound WebGrid example wanted / Help on common design

5 replies. Last post: June 9, 2010 4:37 AM by Eric
Tags :
  • New Discussion
  • New Question
  • New Product Feedback
Eric Member

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

All times are GMT -5. The time now is 2:01 AM.
Previous Next