GridView 双层表头

本文介绍了一种在ASP.NET的GridView控件中实现双层表头的方法,通过重写RowCreated事件,调整表头单元格的数量及内容,实现表头的合并与分层显示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

要实现如下:

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

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

代码如下:

 

ExpandedBlockStart.gif代码
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";                
            }
      }
}

 

 

转载于:https://www.cnblogs.com/andycai/archive/2009/12/04/1616859.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值