GridView产生合并单元格

    protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.Header)
        {
            GridViewRow rowHeader = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Normal);
            Literal li = new Literal();
            li.Text = @"表头文字1</th>
                  <th colspan='2'>表头文字2</th>
                  <th colspan='2'>表头文字3</th>
                  <th>表头文字4</th>
                  </tr>
                  <tr forecolor='" + Color.Green+ "'>";
            li.Text += @"                        
                  <th >表头文字5</th>
                  <th >表头文字6</th>
                  <th colspan='2'>表头文字7</th>
                  <td>88888888888</td></tr>";
                    TableCellCollection cells = e.Row.Cells;
            TableHeaderCell headerCell = new TableHeaderCell();
            //下面的属性设置与 <td rowspan='2'>关键单元格</td> 要一致
            headerCell.RowSpan = 2;
            headerCell.Controls.Add(li);
            rowHeader.Cells.Add(headerCell);

            rowHeader.Cells.Add(headerCell);
            rowHeader.Visible = true;

            //添加到 GridView1
            this.GridView1.Controls[0].Controls.AddAt(0, rowHeader);

        }
    }
}

转载于:https://www.cnblogs.com/neilvension/archive/2006/11/20/995831.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值