问题是我只能从下一行访问某一行的值。这是代码:
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
int s = GridView1.EditIndex;
string constr = "con string";
string statment = "Select Name from tb1 Where [ID] = " + s;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand comm = new SqlCommand(statment, con))
{
con.Open();
Label2.Text = comm.ExecuteScalar().ToString();
con.Close();
}
}
}
例如:
ID Name
Edit Delete Select 1 JOhn
Edit Delete Select 2 SMith
- 如果我在第一行单击编辑和更新,我会得到:
你调用的对象是空的。
- 如果我单击第二行上的编辑和更新,我会从第一行获取值。