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