Repeater 合并单元格

Posted wanggang-java

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Repeater 合并单元格相关的知识,希望对你有一定的参考价值。

aspx:

<table class="tableSearch" style="width: 760px; border: none">
                <tr style="background-color: #EBEEF4; font-size: 13px; font-weight: bold;">
                    <td style="height: 26px;" align="center">
                        订单编号
                    </td>
                    <td style="text-align: center;">
                        PNR
                    </td>
                    <td>
                        乘客姓名
                    </td>
                    <td style="text-align: center;">
                        旧证件号
                    </td>
                    <td style="text-align: center;">
                        新证件号
                    </td>
                    <td style="text-align: center;">
                        请求时间
                    </td>
                    <td style="text-align: center;">
                        处理时间
                    </td>
                    <td>
                        状  态
                    </td>
                </tr>
                <asp:Repeater ID="rprHis" runat="server">
                    <ItemTemplate>
                        <tr style="background-color: #FFFFFF; font-size: 13px;">
                            <td id="HisOrder" runat="server" style="height: 26px; text-align: center;">
                                <asp:HyperLink ID="OrderLink" NavigateUrl=<%# "~/Application/DisplayOrder.aspx?OrderNo=" + Eval("OrderNo") %>
                                    runat="server" Text=<%# Eval("OrderNo") %>> </asp:HyperLink>
                            </td>
                            <td id="HisPNR" runat="server" style="text-align: center;">
                                <%# Eval("pnr") %>
                            </td>
                            <td style="text-align: center;">
                                <asp:Label ID="LabPassengerName" runat="server" Text=<%#Eval("PassengerName") %>></asp:Label>
                            </td>
                            <td style="text-align: center;">
                                <asp:Label ID="Label3" runat="server" Text=<%# Bind("OldCardNo") %>></asp:Label>
                            </td>
                            <td style="text-align: center;">
                                <asp:Label ID="Label4" runat="server" Text=<%# Bind("NewCardNo") %>></asp:Label>
                            </td>
                            <td style="text-align: center;">
                                <asp:Label ID="Label5" runat="server" Text=<%# Bind("RequestTime") %>></asp:Label>
                            </td>
                            <td style="text-align: center;">
                                <asp:Label ID="Label6" runat="server" Text=<%# Bind("ModifyTime") %>></asp:Label>
                            </td>
                            <td style="text-align: center;">
                                <asp:Label ID="Label1" runat="server" Text=<%# GetState(Eval("RequestState").ToString()) %>></asp:Label>
                            </td>
                        </tr>
                    </ItemTemplate>
                </asp:Repeater>
            </table>

合并代码:

for (int i = rprHis.Items.Count - 1; i > 0; i--)
            {
                htmlTableCell oCell_item2 = rprHis.Items[i - 1].FindControl("HisPNR") as HtmlTableCell;

                HtmlTableCell oCell_item1 = rprHis.Items[i].FindControl("HisPNR") as HtmlTableCell;

                oCell_item1.RowSpan = (oCell_item1.RowSpan == -1) ? 1 : oCell_item1.RowSpan;
                oCell_item2.RowSpan = (oCell_item2.RowSpan == -1) ? 1 : oCell_item2.RowSpan;

                if (oCell_item1.InnerText == oCell_item2.InnerText)
                {
                    oCell_item1.Visible = false;
                    oCell_item2.RowSpan += oCell_item1.RowSpan;
                }

                HtmlTableCell oCell2_item2 = rprHis.Items[i - 1].FindControl("HisOrder") as HtmlTableCell;

                HtmlTableCell oCell2_item1 = rprHis.Items[i].FindControl("HisOrder") as HtmlTableCell;

                oCell2_item1.RowSpan = (oCell2_item1.RowSpan == -1) ? 1 : oCell2_item1.RowSpan;
                oCell2_item2.RowSpan = (oCell2_item2.RowSpan == -1) ? 1 : oCell2_item2.RowSpan;

                HyperLink hl1 = rprHis.Items[i - 1].FindControl("OrderLink") as HyperLink;
                HyperLink hl2 = rprHis.Items[i].FindControl("OrderLink") as HyperLink;
                if (hl1.Text == hl2.Text)//必须用这个判断td中不再是文本而是HyperLink控件
                {
                    oCell2_item1.Visible = false;
                    oCell2_item2.RowSpan += oCell2_item1.RowSpan;
                }

            }

 

以上是关于Repeater 合并单元格的主要内容,如果未能解决你的问题,请参考以下文章

Repeater 合并单元格

怎么用代码合并单元格?

c#导出EXCEL合并单元格代码

java poi xwpf操作word生成一个表格怎么合并单元格,求大神指导!

合并单元格的代码错误

html怎么合并单元格