I am using C# ASP.NET on VS2005.
I have a gridview table but it does not have a selection for Enable Editing when I right click on the Smart Tab.
Thus I manually added the edit button with the following code:
AutoGenerateEditButton="True"
The edit button has successfully appeared on my gridview like this:
When I click on the Edit button, the page is refreshed and the row is now editable:
However, when I pressed on the update button, I was brought to the error:
Updating is not supported by data source 'SqlDataSource1' unless UpdateCommand is specified.
http://i.stack.imgur.com/W97K0.png
I have no clue on how I can input or configure the UpdateCommand
because I don't see any background code for the Update
button.
Need help from experienced. Thank you in advance.
Edited: Added INSERT query in SqlDataSource1
, however I still met the same error when I press the Update
button.
You need to re-configure the
SqlDataSource1
control though which you can add support forINSERT
,DELETE
,UPDATE
along withSELECT
.Take a look at this tutorial.
For example, try this out...
Firstly create a method to handle the update record.
Now create the row updating method..
Create Row Cancelling event..
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e) { GridView1.EditIndex = -1; //swicth back to default mode BindGridView(); }
Create row editing...
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e) { GridView1.EditIndex = e.NewEditIndex; BindGridView(); }
There are so many other way out to do this same activity in different fashion. This is most elementary way. Anyways if you find it useful, please mark it as your answer else let me know...
while configurting sqldatasource when you configure the select statement for the gridview,there is a option as "advanced".click on that and then click on 'generate update,insert nad delete statements".