前台代码:
<table cellpadding="0" cellspacing="0" border="1" bordercolor="black" width="100%" style="border-collapse:collapse; border-style:solid;">
<asp:Repeater runat="server" ID="rptInfo">
<HeaderTemplate>
<tr>
<td>科室名称</td>
<td>出诊医生</td>
<td>职称</td>
<td>诊病人数</td>
<td>挂号价格</td>
<td>挂号金额</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td runat="server" id="tdDepName"><%#Eval("dep_name")%></td>
<td><%#Eval("doctor_name")%></td>
<td><%#Eval("title_name")%></td>
<td><%#Eval("register_person")%></td>
<td><%#Eval("price")%></td>
<td><%#Eval("total_money")%></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</FooterTemplate>
</asp:Repeater>
</table>
后台代码:
for (int i = rptInfo.Items.Count - 1; i > 0; i--)
{
HtmlTableCell oCell_previous = rptInfo.Items[i-1].FindControl("tdDepName") as HtmlTableCell;
HtmlTableCell oCell = rptInfo.Items[i].FindControl("tdDepName") as HtmlTableCell;
if(oCell!=null && oCell_previous!=null)
{
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;
}
}
}
用法把合并方法放到邦定之后;就OK了放在数据绑定之后,如下:
this.rptInfo.DataSource = dt;
this.rptInfo.DataBind();
// 合并单元格
for (int i = rptInfo.Items.Count - 1; i > 0; i--)
{
HtmlTableCell oCell_previous = rptInfo.Items[i-1].FindControl("tdName") as HtmlTableCell; //要合并的列td赋值一个ID
HtmlTableCell oCell = rptInfo.Items[i].FindControl("tdName") as HtmlTableCell;
if(oCell_previous!=null && oCell !=null)
{
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;
}
}
}
评论列表: