GridView当中插入一条空记录,显示其它提示一下表头语句
GridView 显示内空如下:编号  部门  金额
1     A部  1000
2     B部   1200
3     C部  1000
4     D部   1200我想改成这样的格式如何实现?
当编号=2 时增加 编号  部门  金额 这行数据编号  部门  金额
1     A部  1000
2     B部   1200
编号  部门  金额
3     C部  1000
4     D部   1200谢谢!

解决方案 »

  1.   

    GridView控件不允许你插入新的记录。 但是,通过它的Empty Data Template的帮助和DetailsView控件可以实现
      

  2.   

    Empty   Data   Template的帮助和DetailsView 如何实现呢?
    谢谢!
      

  3.   


    fengwuleann 请问一下插入空行如何插入空行呢?
      

  4.   

     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);需要适当的修改,因为你每次循环cell.Text 的值都不同
      

  5.   

    忘了告诉你,上面那段代码是写在GridView1_RowDataBound事件里
      

  6.   

            DataTable dt = GetTable();//把gettable()换成你自己的数据就可以了
            if (GetTable().Rows.Count == 0)
            {
                
                dt.Rows.Add(dt.NewRow());
                this.GridView1.DataSource = dt;
                GridView1.DataBind();
                int columnCount = GridView1.Rows[0].Cells.Count;
                GridView1.Rows[0].Cells.Clear();
                GridView1.Rows[0].Cells.Add(new TableCell());
                GridView1.Rows[0].Cells[0].ColumnSpan = columnCount;
                GridView1.Rows[0].Cells[0].Text = "无符合数据,请重新设定搜索条件.";
                GridView1.Rows[0].Cells[0].ForeColor = System.Drawing.Color.Red;
            }