在Gridbox C中更新或删除#

时间:2016-05-24 10:11:21

标签: c# .net gridview

我已经编写了更新,删除,取消和更新的代码。编辑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

My Project GridBox

1 个答案:

答案 0 :(得分:0)

我们可以使用GridView的定义,但这里有几件事要检查/尝试:

您是否指定了数据键名称?

DataKeyNames="id"

您是否尝试在第一行代码上设置断点并逐步找出哪行代码会引发错误?