Gregg's .Net HowTooz

Thursday, July 19, 2007

ASP.NET 2.0 - Allow Users to Create List of Things in Gridview and Store to Database When Complete

I wanted to display a grid with columns that contained various input fields (text boxes, dropdowns, ect.), and I wanted to allow the user to add as many rows to the grid as they needed, and fill in the values for each item. And when they were done, click a button to save the list to the database. I also wanted to be able to populate the grid via databinding (no iterating).

I figured I needed a persistable datastore so I could re-databind whenever the user added a new row. In the end, I ended up using the gridview itself as the persistable store (since gridviews automatically persist themselves via viewstate), and creating code that would generate a datable from the current state of the gridview. (There might be a better way to do this, but this is the way I did it, and it works.)

create_list_of_items_and_save_to_DB_later.txt

0 Comments:

Post a Comment



<< Home