repeater合并单元格
前端
<td id="td_VisitCount" runat="server"> <%# Eval("VisitCount")%> </td>
后台:
绑定数据后,比较是否相等然后再设置RowSpan的属性第一行占用的行数,并把与其相等的隐藏起来
rptData.DataSource = data; rptData.DataBind(); for (int i = rptData.Items.Count - 1; i > 0; i--) { HtmlTableCell oCell_Previous = rptData.Items[i - 1].FindControl("td_VisitCount") as HtmlTableCell; HtmlTableCell oCell = rptData.Items[i].FindControl("td_VisitCount") as HtmlTableCell; oCell.RowSpan = (oCell.RowSpan == -1) ? 1 : oCell.RowSpan; oCell_Previous.RowSpan = (oCell_Previous.RowSpan == -1) ? 1 : oCell_Previous.RowSpan; if (oCell.InnerText == oCell_Previous.InnerText) { oCell.Visible = false; oCell_Previous.RowSpan += oCell.RowSpan; } }
参考博客:http://www.cnblogs.com/LifeKingcn/archive/2012/12/20/2826627.html