下面的代码是gridview控件的使用.
点击更新后,下面红色代码本来应该取得修改后的值,但是怎么还是取得的是原来的值呢?很费解.
是怎么回事呢?
protected void GridView1_RowUpdated(object sender, GridViewUpdateEventArgs e)
{
//Response.Write("<script>alert('"+e.RowIndex.ToString()+"');</script>");
string sqlstr1 = "update userlogin set username='"
+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[0].Controls[0])).Text.ToString().Trim() + "',userpass='"
+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim() + "'"
+" where userid=" + GridView1.DataKeys[e.RowIndex].Value.ToString();
Label1.Text = sqlstr1;
Label2.Text = "\n row index is " + e.RowIndex.ToString();
OleDbCommand mycommand = new OleDbCommand(sqlstr1, conn);
mycommand.CommandText = sqlstr1;
mycommand.CommandType = CommandType.Text;
conn.Open();
mycommand.ExecuteNonQuery();
conn.Close();
GridView1.EditIndex = -1;
bind();
Label1.Visible = true;
}
点击更新后,下面红色代码本来应该取得修改后的值,但是怎么还是取得的是原来的值呢?很费解.
是怎么回事呢?
protected void GridView1_RowUpdated(object sender, GridViewUpdateEventArgs e)
{
//Response.Write("<script>alert('"+e.RowIndex.ToString()+"');</script>");
string sqlstr1 = "update userlogin set username='"
+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[0].Controls[0])).Text.ToString().Trim() + "',userpass='"
+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim() + "'"
+" where userid=" + GridView1.DataKeys[e.RowIndex].Value.ToString();
Label1.Text = sqlstr1;
Label2.Text = "\n row index is " + e.RowIndex.ToString();
OleDbCommand mycommand = new OleDbCommand(sqlstr1, conn);
mycommand.CommandText = sqlstr1;
mycommand.CommandType = CommandType.Text;
conn.Open();
mycommand.ExecuteNonQuery();
conn.Close();
GridView1.EditIndex = -1;
bind();
Label1.Visible = true;
}
浙公网安备 33010602011771号