嘿所有 当我尝试选择命令时,我的代码中出现以下错误 错误 指数超出范围。必须是非负数且小于集合的大小。参数名称:index CODE
hey all when i try to select command the following error comes in my code ERROR Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index CODE
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "Delete") { DepartmentSupervisorInfo.DeleteDeptSupervisor(Convert.ToInt32(GridView1.Rows[Convert.ToInt32(e.CommandArgument)].Cells[2].Text)); GridView1.DataSource = DepartmentSupervisorInfo.getDeptSupervisor(); GridView1.DataBind(); } else if (e.CommandName == "Select") { DataSet ds = DepartmentSupervisorInfo.getDeptSupervisorbyID(Convert.ToInt32(GridView1.Rows[Convert.ToInt32(e.CommandArgument)].Cells[2].Text)); Hdnfld_deptsupid.Value = ds.Tables[0].Rows[0]["DepartmentSupervisorID"].ToString(); Dd_supDepid.DataValueField = ds.Tables[0].Rows[0]["DepartmentID"].ToString(); dd_supEmpid.DataValueField = ds.Tables[0].Rows[0]["EmployeeID"].ToString(); } }此行中的错误
ERROR IN THIS LINE
DataSet ds = DepartmentSupervisorInfo.getDeptSupervisorbyID(Convert.ToInt32(GridView1.Rows[Convert.ToInt32(e.CommandArgument)].Cells[2].Text));推荐答案
问题出在这一行 Problem is at this line GridView1.Rows[Convert.ToInt32(e.CommandArgument)].Cells[2].Text
检查GridView1.Rows是否包含那么多行。它似乎没有。例如,Convert.ToInt32(e.CommandArgument)返回2,但GridView1不包含两行。 检查Convert.ToInt32的值(e.CommandArgument)并修复它
Check that GridView1.Rows contains that many rows. It seems that it does not. For example Convert.ToInt32(e.CommandArgument) is returning 2 but the GridView1 does not contain two rows. Check the value of Convert.ToInt32(e.CommandArgument) and fix it
MessageBox.Show(e.CommandArgument);
//row number is:e.CommandArgument+1 //cell number is:3 MessageBox.Show(GridView1.Rows[Convert.ToInt32(e.CommandArgument)].Cells[2].Text);
调试前面的代码并将结果粘贴给我。
debug the previous code and paste the result to me .
更多推荐
指数超出范围。
发布评论