我收到如下错误:
指数超出范围。必须是非负数且小于集合的大小。参数名称:索引
我的代码是,
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();
}