GridView 多表头解决方法

multiHeaderGridView

protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)

     {

         if (e.Row.RowType == DataControlRowType.Header)

         {

             TableCellCollection tcHeader = e.Row.Cells;//获取表头行的所有单元

             tcHeader.Clear();//清空原有的表头信息

 

             TableHeaderCell th = null;//

             for (int i = 1; i <= 10; i++)

             {//模拟建10个子列

                 th = new TableHeaderCell();

                 th.Text = "方案_" + i;

                 th.Width = 80;

                 tcHeader.Add(th);

 

             }

             GridViewRow rowHeader = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Normal);//建一个表头行

             TableHeaderCell th2;

             th2 = new TableHeaderCell();

             th2.RowSpan = 2;

             th2.Text = "日期";

             th2.Width = 100;

             rowHeader.Cells.Add(th2);

             //

             th2 = new TableHeaderCell();

             th2.ColumnSpan = 10;

             th2.Text = "发车方案";

             rowHeader.Cells.Add(th2);

             //

             th2 = new TableHeaderCell();

             th2.RowSpan = 2;

             th2.Text = "修改";

             rowHeader.Cells.Add(th2);

 

             ((GridView)sender).Controls[0].Controls.AddAt(0, rowHeader);//加到gridview的第一行,也就是表头

 

         }

     }

  

发布了3 篇原创文章 · 获赞 0 · 访问量 3878
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 编程工作室 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览