Reapter合并行

html文件:
<asp:Repeater ID="rptEmployee" runat="server">
            <HeaderTemplate>
                <table border="1" cellpadding="0" cellspacing="1"><tr><td>省份</td><td>城市</td></tr>
            </HeaderTemplate>
            <ItemTemplate>
                <tr><td runat="server" id="divProName"><%#Eval("FirstName")%></td><td><%#Eval("LastName")%></td></tr>
            </ItemTemplate>
            <FooterTemplate>
                </table>
            </FooterTemplate>
        </asp:Repeater>

后台文件:
C#版:
private void BindData()
    {
        this.rptEmployee.DataSource = DBHelper.GetExecuteDataSet("select FirstName,LastName from dbo.Employees group by firstName,LastName", null);
        this.rptEmployee.DataBind();
        for (int i = this.rptEmployee.Items.Count - 1; i > 0; i--)
        {
            HtmlTableCell oCell_pre = this.rptEmployee.Items[i - 1].FindControl("divProName") as HtmlTableCell;
            HtmlTableCell oCell = rptEmployee.Items[i].FindControl("divProName") as HtmlTableCell;
            oCell.RowSpan = oCell.RowSpan == -1 ? 1 : oCell.RowSpan;
            oCell_pre.RowSpan = oCell_pre.RowSpan == -1 ? 1 : oCell_pre.RowSpan;
            if (oCell.InnerHtml==oCell_pre.InnerHtml)
            {
                oCell.Visible = false;
                oCell_pre.RowSpan += oCell.RowSpan;
            }
        }
    }
VB版:
Private Sub BindData()
Me.rptEmployee.DataSource = DBHelper.GetExecuteDataSet("select EmployeeID, LastName, FirstName from Employees order by firstName,EmployeeID desc", Nothing)
        Me.rptEmployee.DataBind()

        For i As Integer = Me.rptEmployee.Items.Count - 1 To 1 Step -1
            Dim cell_pre, cell As HtmlTableCell
            cell_pre = Me.rptEmployee.Items(i - 1).FindControl("divProName") '上一行
            cell = Me.rptEmployee.Items(i).FindControl("divProName") '当前行

            If cell.RowSpan = -1 Then
                cell.RowSpan = 1 '当前行没有合并行,则当行不用合并
            Else
                cell.RowSpan = cell.RowSpan '当行的合并行,等于当前的已经合并的行数
            End If

            If cell_pre.RowSpan = -1 Then
                cell_pre.RowSpan = 1
            Else
                cell_pre.RowSpan = cell_pre.RowSpan
            End If

            If (cell_pre.InnerText = cell.InnerText) Then
                cell.Visible = False
                cell_pre.RowSpan += cell.RowSpan
            End If
        Next

    End Sub

 

转载于:https://www.cnblogs.com/myjacky/p/4492513.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值