指数超出范围。

编程入门 行业动态 更新时间:2024-10-25 20:25:09
本文介绍了指数超出范围。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

嘿所有 当我尝试选择命令时,我的代码中出现以下错误 错误 指数超出范围。必须是非负数且小于集合的大小。参数名称: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 .

更多推荐

指数超出范围。

本文发布于:2023-10-16 12:19:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1497537.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:指数

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!