Here is the image of the UI我在這裏在asp.net初學者,我希望能問,如果你們知道如何解決我的問題。我有一個刪除按鈕,刪除我的datagridview中選中的複選框。每次運行代碼時,它都會給出在int id = Convert.ToInt32(brandgrid.DataKeys[row.RowIndex].Values[0]);
代碼中超出範圍錯誤的參數(索引超出範圍)?ASP.NET GridView的DataKeys錯誤 - 參數超出範圍的指數超出範圍
foreach (GridViewRow row in brandgrid.Rows)
{
int id = Convert.ToInt32(brandgrid.DataKeys[row.RowIndex].Values[0]);
CheckBox chkdel = (CheckBox)row.FindControl("chkDel");
if(chkdel.Checked)
{
//int id = Convert.ToInt32(row.Cells[0].Text);
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "usp_Brand_Delete";
cmd.Parameters.AddWithValue("@login", current);
cmd.Parameters.AddWithValue("@id", id);
cmd.Connection = sqlCon;
sqlCon.Open();
cmd.ExecuteNonQuery();
sqlCon.Close();
}
}
}
你可以發佈你的'GridView'在aspx頁面? – Aruna
貴GridView的第一填補?你是否偶然檢查過沒有列。你調試了嗎?這段代碼執行前的行數和列數是多少? –