私は、更新、削除、キャンセルのコードを書いています& GridBoxの行を編集しています。 キャンセル&編集が正常に動作します。しかし、私は更新をクリックするか、または削除するとき、私は更新するためのGridboxの更新または削除C#
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
@brokenisfixed作成されたIDに従ってデータベースから値を索引付けします。 –
Show_Grid.EditIndex = -1;行がもう編集されていないことを示すだけです... – Mack