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的第一填补?你是否偶然检查过没有列。你调试了吗?这段代码执行前的行数和列数是多少? –