合并单元格

    protected void gridView_PreRender(object sender, EventArgs e)
        {
            MergeRows(gridView);
        }
        //合並單元格
    public static void MergeRows(GridView gridView)

        {
            for (int rowIndex = gridView.Rows.Count - 2; rowIndex >= 0; rowIndex--)//这里不动
            {
                GridViewRow row = gridView.Rows[rowIndex];
                GridViewRow previousRow = gridView.Rows[rowIndex + 1];
                //遍历每一行的每一列(把需要的列进行合并)
                for (int i = 0; i < 9; i++)//i<row.Cells.Count  這裡只需將前8列合并单元格,故i < 9
                {
                    if (row.Cells[i].Text == previousRow.Cells[i].Text)//行合併 RowSpan
                    {
                        row.Cells[i].RowSpan = previousRow.Cells[i].RowSpan < 2 ? 2 : previousRow.Cells[i].RowSpan + 1;
                        previousRow.Cells[i].Visible = false;
                    }
                }
                //补充,合并“合计”//列合并 
                if (previousRow.Cells[7].Text == "合計")
                {
                    previousRow.Cells[7].ColumnSpan = 2;
                    previousRow.Cells[8].Visible = false;
                }
            }
        }
//前端代码          
  <asp:GridView runat="server" ID="gridView" AutoGenerateColumns="False" OnPreRender="gridView_PreRender">
                <Columns>
                    <asp:BoundField DataField="SITE" HeaderText="廠區" ReadOnly="True"></asp:BoundField>
                    <asp:BoundField DataField="LIST_NO" HeaderText="列支單號" ReadOnly="True"></asp:BoundField>
                    <asp:BoundField DataField="ISSUE_LIST_DATE" HeaderText="出名單日期" ReadOnly="True"></asp:BoundField>
                    <asp:BoundField DataField="EXPENSE_DATE" HeaderText="預估列支日期" ReadOnly="True"></asp:BoundField>
                    <asp:BoundField DataField="REMARK" HeaderText="費用說明" ReadOnly="True"></asp:BoundField>
                    <asp:BoundField DataField="COST_TYPE" HeaderText="費用項目" ReadOnly="True"></asp:BoundField>
                    <asp:BoundField DataField="RULE_MODEL" HeaderText="規則模式" ReadOnly="True"></asp:BoundField>
                    <asp:BoundField DataField="GROUP_MAIN_NAME" HeaderText="事業群法人" ReadOnly="True"></asp:BoundField>
                    <asp:BoundField DataField="DISPATCHING_COMPANY" HeaderText="派遣公司" ReadOnly="True"></asp:BoundField>
                    <asp:BoundField DataField="ACTUAL_EMP_CNT" HeaderText="出名單人數" ReadOnly="True"></asp:BoundField>
                    <asp:BoundField DataField="ACTUAL_AMOUNT" HeaderText="出名單金額" ReadOnly="True"></asp:BoundField>
                    <asp:BoundField DataField="WRITE_OFF_AMOUNT" HeaderText="沖賬金額" ReadOnly="True"></asp:BoundField>
                    <asp:BoundField DataField="TOTAL_AMOUNT" HeaderText="列支金額" ReadOnly="True"></asp:BoundField>
                    <asp:BoundField DataField="CHANNEL_AMOUNT" HeaderText="派遣公司金額" ReadOnly="True"></asp:BoundField>
                    <asp:BoundField DataField="AGENT_AMOUNT" HeaderText="代理金額" ReadOnly="True"></asp:BoundField>
                </Columns>
            </asp:GridView>

 效果如下:

​​​​​​​

列1列2列3列4列5列6列7列8列9列10列11列12列13列14
A111oneAA111111
A211111
小计22222
BB111111
小计11111
合计33333

​​​​​​​

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值