repeater合并单元格

<asp:Repeater runat="server" ID="rptInfo">

    <HeaderTemplate>

        <table cellpadding="0" cellspacing="0" border="1" bordercolor="black" width="100%" style="border-collapse:collapse; border-style:solid;">

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

        </table>

    </FooterTemplate>

</asp:Repeater>
View Code
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;

    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;
    }
}
View Code
for (int i = gridInfo.Rows.Count - 1; i > 0; i--)

{

    if (gridInfo.Rows[i].RowType == DataControlRowType.DataRow)

    {

        TableCell tCell = gridInfo.Rows[i].Cells[0];

        TableCell tCell_previous = gridInfo.Rows[i - 1].Cells[0];

        tCell.RowSpan = (tCell.RowSpan == 0) ? 1 : tCell.RowSpan;

 

        tCell_previous.RowSpan = (tCell_previous.RowSpan == 0) ? 1 : tCell_previous.RowSpan;

 

        if (tCell.Text == tCell_previous.Text)

        {

            tCell.Visible = false;

            tCell_previous.RowSpan += tCell.RowSpan;

        }

    }

}
View Code

摘抄自https://www.cnblogs.com/zhmore/archive/2009/04/22/1440979.html

posted @ 2018-06-04 09:39  江境纣州  阅读(12)  评论(0编辑  收藏  举报