-4

我收到如下错误:

指数超出范围。必须是非负数且小于集合的大小。参数名称:索引

我的代码是,

int index = 0;
        GridViewRow gvrow;
        GridViewRow previousRow;
        if (e.CommandName == "Up")
        {
            index = Convert.ToInt32(e.CommandArgument);
            gvrow = GridView2.Rows[index];
            previousRow = GridView2.Rows[index - 1];
            int mobilePriority = Convert.ToInt32(GridView2.DataKeys[gvrow.RowIndex].Value.ToString());
            int mobileId = Convert.ToInt32(gvrow.Cells[0].Text);
            int previousId = Convert.ToInt32(previousRow.Cells[0].Text);
            con.Open();
            cmd = new SqlCommand("update AppointmentMaster set Priority='" + (mobilePriority - 1) + "' where AppointmentId='" + mobileId + "'; update AppointmentMaster set Priority='" + (mobilePriority) + "' where AppointmentId='" + previousId + "'", con);
            cmd.ExecuteNonQuery();
            con.Close();
        }    
4

1 回答 1

1
previousRow = GridView2.Rows[index - 1];

(index - 1) 将是 -1,因为 index == 0。

于 2013-06-07T16:58:40.633 回答