Wednesday, August 11, 2010

How to pass a DataSet across projects to a GridView in ASP.NET 2.0?

I am using the new Visual Studio 2005 and ASP.NET 2.0 (C#) to create a 3-tier web application with the middle tier (business logic and database access) in a DLL file created in a separate project in VS2005 from the web site. How do I pass data back and forth between the DLL and the web site to populate a GridView component and still be able to do the standard Update, Insert, Deletes on the data? All the examples in books and on the web assume that your data source objects are located in the same project as the web site (2-tier design and a bad practice).





I can create and pass a standard DataSet object and then link it to a GridView using DataSource/DataBind. This displays data, but when I click the built in Edit/Delete links, nothing happens (screen just reposts, no errors). I assume that I have to add some code in the update/delete event handlers, but what? And how do I pass the modified data back to update the database? Books, websites, examples? Help!How to pass a DataSet across projects to a GridView in ASP.NET 2.0?
You would have to create a custom Update and delete button when working with a data set. create a template column and have your update and delete buttons there.





In your Gridview databound event make sure you specify the row of the grid to the command attribute of the buttons. That way you know which row you are clicking. Then when you click update or delete in the appropriate event just update the database. then make sure you databind your dataset again before you display your grid so that the changes will reflect on the screen.

No comments:

Post a Comment