前端html
<td id="td_VisitCount" runat="server"> <%# Eval("VisitCount")%> </td>
後臺:前端
綁定數據後,比較是否相等而後再設置RowSpan的屬性第一行佔用的行數,並把與其相等的隱藏起來spa
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.htmlcode