前台:
<td runat="server" id="tdName"><%#Eval("td_name")%></td>
后台:
rptList.DataSource = pds; rptList.DataBind(); //合并方法放到数据邦定之后 for (int i = rptList.Items.Count - 1; i > 0; i--) { HtmlTableCell oCell_Previous = rptList.Items[i - 1].FindControl("tdName") as HtmlTableCell; HtmlTableCell oCell = rptList.Items[i].FindControl("tdName") 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; } }