JBoss
JBoss

Reputation: 776

ASP.NET GridView set with DataSet, can't edit rows

I'm having the following problem:

What I have is a search function that runs a query on my database using a SqlDataAdapter. I then use:

DataSet ds = new DataSet();
dataAdapter.Fill(ds, "table title");
gridView1.DataSource = ds;
gridView1.DataBind();

I originally got an error that I then had both a dataSource and dataSourceId, so I cleared the previously used ID. The code works, I can search the table and my query will return rows and update the table. The problem is that I want the data that it returns to be editable. I have my grid view editable, and before I run the query, I can edit the rows of the table. But after the search is run, and the gridView is filled with my DataSet, I'm unable to update the rows. If I click the edit button, it gives me an error saying the RowEditing event wasn't handled.

I looked into that event, and understand what's happening, if I were to program in the events for RowEditing/RowUpdating/RowUpdated etc. I could get it to work, but is there no better way to do this? Is there a simpler way to set my dataSource in C# and be able to maintain the editablity of the rows?

Thanks a lot!

Upvotes: 0

Views: 470

Answers (1)

Simon Houlton
Simon Houlton

Reputation: 182

I suppose part of the question would be would you want to? I guess you're looking for a SaveDataChanges() method which brings about a few design concerns. One is you have to remember that web pages are stateless so to an extent your web page post isn't aware of the data it's just pulled and bound to the UI. The grid view control in a round about way nicely gets the user to help you out here and click update on the row they've amended. With this you have your event handler and you can just focus on the data that's been changed and just send one UPDATE statement.

Upvotes: 0

Related Questions