• Repeater 合并单元格


    前途页面:

     <asp:Repeater ID="rptList" runat="server" OnPreRender="rptList_PreRender">
                    <ItemTemplate>
                    <tr>
                        <td align="center" runat="server" id="Num">
                            <%#Eval("Num")%>
                        </td>
                        <td align="center" runat="server" id="ProClassification">
                            <%#Eval("ProClassification")%>
                        </td>
                        <td align="center" runat="server" id="ProName">
                            <%#Eval("ItemName")%>
                        </td>
                        <td align="center" runat="server" id="Unit">
                            <%#Eval("Unit")%>
                        </td>
                        <td align="center" runat="server" id="Quantity">
                            <%#Eval("Quantity")%>
                        </td>
                    </tr>
                    </ItemTemplate>
                </asp:Repeater>

    注意点:

    1)绑定Repeater控件的OnPreRender方法

    2)td单元格添加runat="server"和id属性

    后台页面:
      

            protected void rptList_PreRender(object sender, EventArgs e)
            {
                string[] IDs = { "Num", "ProClassification", "ProName", "Unit", "Quantity" };
                for (int i = rptList.Items.Count - 1; i > 0; i--)
                {
                    for (int j = 0; j < IDs.Length; j++)
                    {
                        //IDs[j]是需要合并列的列名
                        HtmlTableCell oCell_previous = rptList.Items[i - 1].FindControl(IDs[j]) as HtmlTableCell;
                        HtmlTableCell oCell = rptList.Items[i].FindControl(IDs[j]) 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)
                            {
                                if (oCell.InnerText.Trim()!="")//空单元格不执行合并操作
                                {
                                    oCell.Visible = false;
                                    oCell_previous.RowSpan += oCell.RowSpan;
                                }                            
                            }
                        }
                    }           
                                   
                }
            }
  • 相关阅读:
    集成学习值Adaboost算法原理和代码小结(转载)
    集成学习原理小结(转载)
    2019阿里校招测评题,光明小学完全图最短路径问题(python实现)
    第八节、图片分割之GrabCut算法、分水岭算法
    Scala2.11.8 spark2.3.1 mongodb connector 2.3.0
    spark 实现动态日期读取
    Idea 201601注册码
    linux下的crontab服务
    spark MySQL jar 包
    scala 日期格式转换
  • 原文地址:https://www.cnblogs.com/SunXiaoLin/p/3391090.html
Copyright © 2020-2023  润新知