gridview在数据绑定后如果数据行较少,会出现表头,行高很宽的现象,影响页面美观,这时可以人为地添加几个空行,让gridview始终有分页要求的数据行。
protected void gvyearaward_RowCreated(object sender, GridViewRowEventArgs e)
{
int numCount = 0;
if (e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.Header)
{
//如果想使第1列不可见,则将它的可见性设为false
}
int num = 0;
num = gvyearaward.Rows.Count;
if (e.Row.RowType == DataControlRowType.Footer)
{ int left = gvyearaward.PageSize - num;
int numCol = gvyearaward.Rows[0].Cells.Count;
for(int i=0;i<left;i++)
{ GridViewRow row =
new GridViewRow(-1,-1,DataControlRowType.EmptyDataRow,DataControlRowState.Normal);
for (int j = 0; j < numCol; j++)
{ TableCell cell = new TableCell();
cell.Text = " ";
row.Cells.Add(cell);
}
gvyearaward.Controls[0].Controls.AddAt(num+1+i,row);
}
}
}