Last post Apr 12, 2011 09:46 PM by Decker Dong - MSFT
Apr 10, 2011 12:02 AM|houmy|LINK
I have a gridview with a sql datasource. When the select statement for the datasource is in the sqldatasource control then everything works fine and i can view the data and update it through the gridview. When I take away the selecet statement and insetad
use a sqldatasource.SelectCommand in my code behind then I can only view the data in the gridview but cannot edit. When I try to edit/update data the data being edited goes back to original and the gridview stays in edit mode. After hitting cancel on the gridview
then the old data still shows. Any ideas about this? "Optimistic Concurncy" is also switched off so that is not the problem.
Apr 10, 2011 05:25 AM|smirnov|LINK
You need to handle the RowUpdating event of GridView to assign the values to parameters manually:
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
string id = GridView1.DataKeys[e.RowIndex].Value.ToString();
string txt = ((TextBox)GridView1.Rows[e.RowIndex].Cells.Controls).Text;
SqlDataSource1.UpdateParameters["id"].DefaultValue = id;
SqlDataSource1.UpdateParameters["txt"].DefaultValue = txt;
SqlDataSource1.SelectCommand = "...";
Apr 12, 2011 09:46 PM|decker dong - msft|LINK
How did you code?
Maybe you should offer us some parts of your codes.
PS：This is a detailed sample for you to refer about Editing/Inserting/Updating with SqlDataSource：http://csharpdotnetfreak.blogspot.com/2009/05/gridview-sqldatasource-insert-edit.html