我尝试在绑定数据后更改gridview大小并重命名标题,但我收到错误“索引超出范围”,因为我的数据超过100px,如何解决?
conn.Open();
cmdString = "SQL";
cmd = new SqlCommand(cmdString, conn);
cmd.Parameters.AddWithValue("@courseID", CourseID);
dtr = cmd.ExecuteReader();
gvAssignment.DataSource = dtr;
gvAssignment.Columns[7].ItemStyle.Width = Unit.Pixel(100);
gvAssignment.DataBind();
dtr.Close();
conn.Close();
另一种方法没有错误,但大小不会更改为 100
protected void gvAssignment_RowDataBound(object sender, GridViewRowEventArgs e)
{
e.Row.Cells[7].Width = 100;
}