代码
<table width="100%" id="mytable" >
<tr align="center">
<th>学号</th><th>姓名</th><th>起止时间</th> <th>学习(或工作)单位</th> <th>职务</th> <th>证明人</th> <th>备注</th>
</tr>
<asp:Repeater ID="Repeater1" runat="server" onprerender="Repeater1_PreRender">
<ItemTemplate>
<tr><td id="tdxuehao" runat="server"> <%#Eval("xuehao") %></td><td id="tdxsname" runat="server"> <%#Eval("xsname")%></td><td> <%#Eval("qzsj")%></td> <td> <%#Eval("grjl")%></td> <td> <%#Eval("zw")%></td> <td> <%#Eval("zmr")%></td> <td> <%#Eval("bz")%></td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>
<tr align="center">
<th>学号</th><th>姓名</th><th>起止时间</th> <th>学习(或工作)单位</th> <th>职务</th> <th>证明人</th> <th>备注</th>
</tr>
<asp:Repeater ID="Repeater1" runat="server" onprerender="Repeater1_PreRender">
<ItemTemplate>
<tr><td id="tdxuehao" runat="server"> <%#Eval("xuehao") %></td><td id="tdxsname" runat="server"> <%#Eval("xsname")%></td><td> <%#Eval("qzsj")%></td> <td> <%#Eval("grjl")%></td> <td> <%#Eval("zw")%></td> <td> <%#Eval("zmr")%></td> <td> <%#Eval("bz")%></td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>
代码
protected void Repeater1_PreRender(object sender, EventArgs e)
{
for (int i = Repeater1.Items.Count - 1; i > 0; i--)
{
//tcid是需要合并列的列名
HtmlTableCell oCell_previous = Repeater1.Items[i - 1].FindControl("tdxuehao") as HtmlTableCell;
HtmlTableCell oCell = Repeater1.Items[i].FindControl("tdxuehao") 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;
}
}
HtmlTableCell nameprevious = Repeater1.Items[i - 1].FindControl("tdxsname") as HtmlTableCell;
HtmlTableCell name = Repeater1.Items[i].FindControl("tdxsname") as HtmlTableCell;
if (nameprevious != null && name != null)
{
name.RowSpan = (name.RowSpan == -1) ? 1 : name.RowSpan;
nameprevious.RowSpan = (nameprevious.RowSpan == -1) ? 1 : nameprevious.RowSpan;
if (name.InnerText == nameprevious.InnerText)
{
name.Visible = false;
nameprevious.RowSpan += name.RowSpan;
}
}
}
}
{
for (int i = Repeater1.Items.Count - 1; i > 0; i--)
{
//tcid是需要合并列的列名
HtmlTableCell oCell_previous = Repeater1.Items[i - 1].FindControl("tdxuehao") as HtmlTableCell;
HtmlTableCell oCell = Repeater1.Items[i].FindControl("tdxuehao") 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;
}
}
HtmlTableCell nameprevious = Repeater1.Items[i - 1].FindControl("tdxsname") as HtmlTableCell;
HtmlTableCell name = Repeater1.Items[i].FindControl("tdxsname") as HtmlTableCell;
if (nameprevious != null && name != null)
{
name.RowSpan = (name.RowSpan == -1) ? 1 : name.RowSpan;
nameprevious.RowSpan = (nameprevious.RowSpan == -1) ? 1 : nameprevious.RowSpan;
if (name.InnerText == nameprevious.InnerText)
{
name.Visible = false;
nameprevious.RowSpan += name.RowSpan;
}
}
}
}