zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    好久没来园子里转了,最近在学ssh,有个小问题提出来
    ClearType使用的问题
    Metro中访问特定设备的方法
    UMDF驱动程序快速上手
    关于GPS使用上的一个怪异问题
    一个不能创建WINCE6.0工程的问题
    Metro开发小记
    在WINPE中添加驱动
    DOS命令活用
    METRO开发中的多语言处理
  • 原文地址:https://www.cnblogs.com/myjacky/p/4492513.html
Copyright © 2011-2022 走看看