• Repeater双层嵌套


    前台代码:

     <div>
            <asp:Repeater ID="rptOne" runat="server" OnItemDataBound="rptOne_ItemDataBound" >
                <ItemTemplate>
                    <div >
                        <%# Eval("DepartName") %>
                        <div>
                            <asp:Repeater ID="rptTwo" runat="server">
                                <ItemTemplate>
                                    <%# Eval("StaffName") %>
                                </ItemTemplate>
                            </asp:Repeater>
                        </div>
                    </div>
                </ItemTemplate>
            </asp:Repeater>
        </div>
    

    后台代码:

    public partial class WebForm1 : System.Web.UI.Page
        {
            StaffInfoBLL sbll = new StaffInfoBLL();
            DepartmentInfoBLL dbll = new DepartmentInfoBLL();
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    this.rptOne.DataSource = dbll.GetAll();
                    Session["DepartAll"] = sbll.GetAll();
                    this.rptOne.DataBind();
                }
            }
    
            protected void rptOne_ItemDataBound(object sender, RepeaterItemEventArgs e)
            {
                if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
                {
                    Repeater rptWo = e.Item.FindControl("rptTwo") as Repeater;
                    DepartmentInfo d = e.Item.DataItem as DepartmentInfo;
                    IList<StaffInfo> list = Session["DepartAll"] as IList<StaffInfo>;
                    if (list != null)
                    {
                        rptWo.DataSource = list.Where(p=>p.DepartmentInfo.DepartId==d.DepartId);
                        rptWo.DataBind();
                    }
                }
            }
        }
    

      

  • 相关阅读:
    洛谷
    洛谷
    洛谷
    洛谷
    模板
    .
    洛谷
    洛谷
    洛谷
    poj 2955"Brackets"(区间DP)
  • 原文地址:https://www.cnblogs.com/liujie1111/p/3648432.html
Copyright © 2020-2023  润新知