protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
GridViewRow rowSeparator = new GridViewRow(0, 0, DataControlRowType.DataRow, DataControlRowState.Normal);
                                      TableCell separatorCell = new TableCell();
                    separatorCell.ColumnSpan = 1;
                    rowSeparator.Cells.Add(separatorCell);
                    
                    rowSeparator.Visible = true;
                    //在GridView中的相应行插入行
                    GridView1.Controls[0].Controls.AddAt(this.GridView1.Rows.Count, rowSeparator);
}我这么写,但是运行后并没有添加一行,应该怎么写呢?

解决方案 »

  1.   

    给GridView加行   选择更改数据源是最合适的。
      

  2.   

    参考GRIDVIEW手动增加行:
    http://www.cnblogs.com/psforever/archive/2011/02/23/1963207.html
      

  3.   

    应该这么写protected void GrvCode_RowCreated(object sender, GridViewRowEventArgs e)
         {
             int num = 0;
             num = GrvCode.Rows.Count;
             if (e.Row.RowType == DataControlRowType.Footer)
             {
                 int left = GrvCode.PageSize - num;
                 int numCol = GrvCode.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 = "&nbsp";
                         row.Cells.Add(cell);
                     }
                     GrvCode.Controls[0].Controls.AddAt(num+1+i,row);
                 }
             }
         }