How to handle update events on a ASP.NET GridView?
- by Bogdan M
Hello,
This may sound silly, but I need to find out how to handle an Update event from a GridView.
First of all, I have a DataSet, where there is a typed DataTable with a typed TableAdapter,
based on a "select all query", with auto-generated Insert, Update, and Delete methods.
Then, in my aspx page, I have an ObjectDataSource related to my typed TableAdapter on Select,
Insert, Update and Delete methods. Finnally, I have a GridView bound to this ObjectDataSource,
with default Edit, Update and Cancel links.
How should I implement the edit functionality? Should I have something like this?
protected void GridView_RowEditing(object sender, GridViewEditEventArgs e)
{
using(MyTableAdapter ta = new MyTableAdapter())
{
ta.Update(...);
TypedDataTable dt = ta.GetRecords();
this.GridView.DataSource = dt;
this.GridView.DataBind();
}
}
In this scenario, I have the feeling that I update some changes to the DB, then I retrive and bind all the data,
and not only the modified parts.
Is there any way to update only the DataSet, and this to update on his turn the DataBase and the GridView?
I do not want to retrive all the data after a CRUD operations is performed, I just want to retrive the changes made.
Thanks.
PS: I'm using .NET 3.5 and VS 2008 with SP1.