repeater相同行合并

代码
<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">&nbsp;<%#Eval("xuehao"%></td><td id="tdxsname" runat="server">&nbsp;<%#Eval("xsname")%></td><td>&nbsp;<%#Eval("qzsj")%></td> <td>&nbsp;<%#Eval("grjl")%></td> <td>&nbsp;<%#Eval("zw")%></td> <td>&nbsp;<%#Eval("zmr")%></td> <td>&nbsp;<%#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;
                    }
                }
            }


        }

 

 

posted on 2010-10-29 16:30  叶子绿了  阅读(...)  评论(...编辑  收藏

导航