GridView 双层表头

GridView 中实现双层表头的主要思路是通过GridView 的RowCreated 方法重写表头.

要实现如下:

      NPRB表單號&基本資料                        |預計出關日期     |    實際出關日期   |  Delay差異天數

---------------------------------------------------------------------------------------------
NPRB_NO  | BU  |  PM  |  MODEL_NAME   |DESIGN_PLN    |  DESIGN_ACT   |   DESIGN_DEL

代码如下:

 

代码
protected void gdvReport_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
        {
            TableCellCollection tcl 
= e.Row.Cells; 
            tcl.Clear();
            tcl.Add(
new TableHeaderCell());
            tcl[
0].ColumnSpan = 4;             //合并列
            tcl[0].Text = "NPRB表單號&基本資料";

            tcl.Add(
new TableHeaderCell());
            tcl[
1].Text = "預計出關日期";

            tcl.Add(
new TableHeaderCell());
            tcl[
2].Text = "實際出關日期";

            tcl.Add(
new TableHeaderCell());
            tcl[
3].Text = "Delay差異天數</th></tr><tr>"// 这里第一层已经写完,以下是第二层

            tcl.Add(
new TableHeaderCell());
            tcl[
4].Text = "NPRB_NO";
            tcl.Add(
new TableHeaderCell());
            tcl[
5].Text = "BU";
            tcl.Add(
new TableHeaderCell());
            tcl[
6].Text = "PM";
            tcl.Add(
new TableHeaderCell());
            tcl[
7].Text = "MODEL_NAME";

                tcl.Add(
new TableHeaderCell());
                tcl[
8].Text = this.ddlPhase.SelectedValue + "_PLN";

                tcl.Add(
new TableHeaderCell());
                tcl[
9].Text = this.ddlPhase.SelectedValue + "_ACT";

                tcl.Add(
new TableHeaderCell());
                tcl[
10].Text = this.ddlPhase.SelectedValue + "_DEL";                
            }
      }
}

 

 

posted on 2009-12-04 11:43  AndyCai  阅读(672)  评论(0编辑  收藏  举报

导航