gridview 索引超出范围。必须为非负值并小于集合大小。!!!
索引超出范围。必须为非负值并小于集合大小。参数名: index
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.ArgumentOutOfRangeException: 索引超出范围。必须为非负值并小于集合大小。
参数名: index
拜求高手解决!!! 程序如下!
protected void Search_Click(object sender, EventArgs e)
{
SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["sqlconnection"].ConnectionString);
myConnection.Open();
string cmdText = "SELECT Users.RoleID,Users.BID ,CheckDetail.CDID,CheckDetail.Sum, CheckDetail.CheckTime, Role.RoleName FROM CheckDetail INNER JOIN Users ON CheckDetail.UserID = Users.UserID INNER JOIN Role ON Users.RoleID = Role.RoleID WHERE Checked='" + lblUN.Text.Trim() + "' AND CheckYear = '" + ddlCY.Text.Trim() + "' ";
SqlCommand cmd = new SqlCommand(cmdText, myConnection);
SqlDataReader sdr = cmd.ExecuteReader();
GvUserList.DataSource = sdr;
GvUserList.DataKeyNames = new string[] { "CDID" };
GvUserList.DataBind();
sdr.Close();
myConnection.Close();
int RowsNum, i, CRoleID = 0, CBID = 0, Sum1gs = 0, Sum2gs = 0, Sum3gs = 0, Sum4gs = 0, Sum5gs = 0, Sum6gs = 0, Sum7gs = 0, Sum8gs = 0, Sum12gs = 0, Sum13gs = 0, Sum14gs = 0, Sum15gs = 0, Sum16gs = 0;
double Sum = 0.00, Sum1 = 0.00, Sum2 = 0.00, Sum3 = 0.00, Sum4 = 0.00, Sum5 = 0.00, Sum6 = 0.00, Sum7 = 0.00, Sum8 = 0.00, Sum12 = 0.00, Sum13 = 0.00, Sum14 = 0.00, Sum15 = 0.00, Sum16 = 0.00, Leader = 0.00;
RowsNum = GvUserList.Rows.Count;
for (i = 0; i < RowsNum; i++)
{
CRoleID = Int32.Parse(GvUserList.Rows[i].Cells[3].Text);
CBID = Int32.Parse(GvUserList.Rows[i].Cells[4].Text);
//打分
if (Int32.Parse(CRedID.Text) == 6)
{
switch (CRoleID)
{
case 2:
{
Sum2 = Sum2 + double.Parse(GvUserList.Rows[i].Cells[1].Text);
Sum2gs = Sum2gs + 1;
} break;
case 3:
{
Sum3 = Sum3 + double.Parse(GvUserList.Rows[i].Cells[1].Text);
Sum3gs = Sum3gs + 1;
} break;
case 7:
{
Sum7 = Sum7 + double.Parse(GvUserList.Rows[i].Cells[1].Text);
Sum7gs = Sum7gs + 1;
} break;
case 8:
{
Sum8 = Sum8 + double.Parse(GvUserList.Rows[i].Cells[1].Text);
Sum8gs = Sum8gs + 1;
} break;
case 12:
{
Sum12 = double.Parse(GvUserList.Rows[i].Cells[1].Text);
Sum12gs = 1;
} break;
case 13:
{
Sum13 = double.Parse(GvUserList.Rows[i].Cells[1].Text);
Sum13gs = 1;
} break;
case 16:
{
Sum16 = Sum16 + double.Parse(GvUserList.Rows[i].Cells[1].Text);
Sum16gs = Sum16gs + 1;
} break;
default: break;
}
Sum=Sum2+Sum3+Sum7+Sum8+Sum12+Sum13+Sum16
}
Label1.Text = Sum.ToString();
} --------------------编程问答-------------------- 索引超出范围。必须为非负值并小于集合大小。
楼主,这种问题都解决不了??????????? --------------------编程问答-------------------- i < RowsNum-1 --------------------编程问答-------------------- 新手! ~见笑了 我不知道哪里有错误啊!~ 望给予解决方法!谢谢了!~~! --------------------编程问答-------------------- 谢谢楼上的英雄了!~ 解决了!~ --------------------编程问答-------------------- 既然问题解决了,
就来接分
--------------------编程问答-------------------- i < RowsNum-1 --------------------编程问答-------------------- 接分吧 --------------------编程问答-------------------- 抢分..哈哈 --------------------编程问答-------------------- 凑热闹 --------------------编程问答-------------------- 为什么我给分 系统提示我密码验证有错误啊?
补充:.NET技术 , ASP.NET