索引超出范围。必须为非负值并小于集合大小。参数名: index(三层)
protected void gvDepartmentInfo_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)//判断行类型
{
string gvId = gvDepartmentInfo.DataKeys[e.Row.RowIndex].Value.ToString();//得到部门id 是这里,怎么改啊
tb_DepartInfo d = DepartManager.GetDepartByID(gvId);
e.Row.Cells[1].Text = d.IDepartID;
e.Row.Cells[2].Text = d.VcDepartName;
e.Row.Cells[3].Text = d.Td_OrderNum.ToString();
LinkButton lbt_Delete = (LinkButton)e.Row.FindControl("lbt_Delete");//实例化按钮控件
lbt_Delete.CommandArgument = gvId;//指定删除按钮的关联参数
lbt_Delete.Attributes.Add("onclick", "return confirm('确定要删除吗?');");
}
}
------解决方案--------------------检查所有通过索引访问的地方,错误是越界
------解决方案--------------------gvDepartmentInfo.DataKeys[e.Row.RowIndex] <-- 这里越界了,索引超出范围.
DataKeys中包含的元素个数上限 < e.Row.RowIndex