码迷,mamicode.com
首页 > 其他好文 > 详细

Reapter合并行

时间:2015-05-10 18:52:21      阅读:161      评论:0      收藏:0      [点我收藏+]

标签:

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

 

Reapter合并行

标签:

原文地址:http://www.cnblogs.com/myjacky/p/4492513.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!