repeater合并单元格

前端

 <td id="td_VisitCount" runat="server"> <%# Eval("VisitCount")%> </td>

后台:

绑定数据后,比较是否相等然后再设置RowSpan的属性第一行占用的行数,并把与其相等的隐藏起来

     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.html

posted on 2017-06-22 11:48  不悔梦归处  阅读(190)  评论(0编辑  收藏  举报

导航