大智

快乐工作中生活

 

Gridview 增加多个空行。

// 自动填充的行数
  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
= "&nbsp;";
          row.Cells.Add(cell);
        }
        GridView1.Controls[
0].Controls.AddAt(numCount + 1 + i, row);
      }
    }
  }

posted on 2008-10-23 17:28  lgzh  阅读(3128)  评论(1编辑  收藏  举报

导航