views:

69

answers:

1

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.

A: 

This is not really possible using the objects you have here. In particular, the ObjectDataSource is fairly limited in this regard. It would certainly be possible using a DataSet, but then you've got to do more of the grunt work.

I suggest you dive into a more robust ORM system.

Bryan