当我单击“编辑”时,我有一个datagridview,我可以修改文本,但是当我单击“保存”时,该行变为空,我不明白为什么会这样。
这是我单击保存后的图像。 [
这是保存代码。
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
GridViewRow row = GridView1.Rows[e.RowIndex];
TextBox txtID = row.FindControl("txtID") as TextBox;
TextBox txtName = row.FindControl("txtName") as TextBox;
TextBox txtCity= row.FindControl("txtCity") as TextBox;
foreach (Emp obj in lEmp)
{
if (obj.ID == int.Parse(txtID.Text))
{
obj.ID = int.Parse(txtID.Text);
obj.Name = txtName.Text;
obj.City = txtCity.Text;
break;
}
}
BindGridList("", "");
GridView1.EditIndex = -1;
}