【发布时间】:2016-05-24 10:11:20
【问题描述】:
我已经编写了用于更新、删除、取消和编辑 GridBox 中的行的代码。 取消和编辑工作正常。但是当我点击更新或删除时,我收到一条错误提示
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
对于更新,代码是
protected void Show_Grid_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
int id = int.Parse(Show_Grid.DataKeys[e.RowIndex].Value.ToString());
TextBox txt_title = (TextBox)Show_Grid.Rows[e.RowIndex].FindControl("Title");
TextBox txt_desc = (TextBox)Show_Grid.Rows[e.RowIndex].FindControl("Description");
TextBox drop_prior = (TextBox)Show_Grid.Rows[e.RowIndex].FindControl("Priority");
Update_todo(id, txt_title.Text, txt_desc.Text, drop_prior.Text);
Show_Grid.EditIndex = -1;
DataBind();
}
数据库包含,
id, Title, Description, Priority
【问题讨论】:
-
为什么要分配“Show_Grid.EditIndex = -1;”?
-
@brokenisfixed 根据创建的 ID 索引数据库中的值。
-
Show_Grid.EditIndex = -1;应该只是表明该行不再被编辑...