Gridview 增加多个空行。

来源:互联网 发布:防范电信网络诈骗图片 编辑:程序博客网 时间:2024/05/17 10:07
// 自动填充的行数   int numCount = 0;   protected void Page_Load(object sender, EventArgs e)   {     if (!Page.IsPostBack)     {       GridView1.DataSource = CreateDataSourceByXianhuiMeng();       GridView1.DataBind();     }   }   protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)   {     if (e.Row.RowType == DataControlRowType.DataRow)     {       // 计算自动填充的行数       numCount++;     }     if (e.Row.RowType == DataControlRowType.Footer)     {       // 计算完毕,在此添加缺少的行       int toLeft = TotalRowCount - numCount;       int numCols = GridView1.Rows[0].Cells.Count;       for (int i = 0; i < toLeft; i++)       {         GridViewRow row = new GridViewRow(-1, -1, DataControlRowType.EmptyDataRow, DataControlRowState.Normal);         for (int j = 0; j < numCols; j++)         {           TableCell cell = new TableCell();           cell.Text = " ";           row.Cells.Add(cell);         }         GridView1.Controls[0].Controls.AddAt(numCount + 1 + i, row);       }     }   } 


 

原创粉丝点击