把下面的if语句写在 RowCreated事件里面!
- 方法一:C# code
- protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.Header) { e.Row.Cells[0].Width = 480; e.Row.Cells[1].Width = 200; } }
方法二:
GridView1.Columns[0].ItemStyle.Width = 100;
补充:
Gridview中使用AutoGenerateColumns="true",也就是自动填充数据