//=----------------------------------------------------------------------非编辑状态
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
//string id = ( ( Label )GridView1.Rows[e.RowIndex].FindControl( "Label1" ) ).Text;
string FoodTemp = ( ( Label )GridView1.Rows[e.NewEditIndex].FindControl( "Label1" ) ).Text;
//这里就获取到了当前行中 Label1的数据了NewEditIndex
//Response.Write( "<script type='text/javascript'>alert('" + FoodTemp + "')</script>" );
GridView1.EditIndex = e.NewEditIndex;
BindGridView();
}
//-----------------------------------------------------------------------------编辑状态
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string id = ( ( Label )GridView1.Rows[e.RowIndex].FindControl( "IdLabel" ) ).Text;
//这里就是获取到了当前行中ID Label的数据了e.RowIndex
//string id = ( ( TextBox )this.GridView1.Rows[e.RowIndex].Cells[0].Controls[0] ).Text.ToString();
// Response.Write( "<script type='text/javascript'>alert('"+id+"')</script>" );
DB db = new DB();
DataTable dt = new DataTable();
string Ntext = ( ( TextBox )this.GridView1.Rows[e.RowIndex].Cells[1].Controls[0] ).Text.ToString();
//这里则是获取到了当前行中第2列的值e.RowIndex
string Ctext = ( ( TextBox )this.GridView1.Rows[e.RowIndex].Cells[2].Controls[0] ).Text.ToString();
string BFtext = ( ( DropDownList )GridView1.Rows[e.RowIndex].FindControl( "DropDownList1" ) ).Text;
//Response.Write( "<script type='text/javascript'>alert('" + BFtext + "')</script>" );
dt = db.GetTable( "UPDATE testtable SET name ='" + Ntext + "',city='" + Ctext + "',bestfood='" + BFtext + "' WHERE id=" + id );
GridView1.EditIndex = -1;
BindGridView();
}