// 自动填充的行数
  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);
      }
    }
  }

相关文章:

  • 2021-07-25
  • 2021-10-16
  • 2021-07-13
  • 2022-12-23
  • 2022-12-23
  • 2021-08-02
  • 2021-11-23
猜你喜欢
  • 2022-12-23
  • 2021-12-30
  • 2022-12-23
  • 2022-12-23
  • 2022-01-04
  • 2022-12-23
  • 2021-12-06
相关资源
相似解决方案