Repeater嵌套(灵活的)

页面代码

<form id="form1" runat="server">
    <asp:Repeater ID="rptCategories" runat="server" OnItemCommand="rptCategories_ItemCommand">
        <HeaderTemplate>
            <table width="100%" border="1" cellspacing="0" cellpadding="0">
        </HeaderTemplate>
        <ItemTemplate>
            <!--分类名称-->
            <tr>
                <th>
                    <asp:LinkButton ID="LinkButton1" CommandName=‘<%#DataBinder.Eval(Container.DataItem, "ID") %>‘
                        runat="server"><%#DataBinder.Eval(Container.DataItem, "ID")%></asp:LinkButton>
                        <input type="button" value="收" onclick="aa()" />
                </th>
                <th>
                   <label runat="server" id="lbl"> <%# DataBinder.Eval(Container.DataItem, "loginid")%></label>
                </th>
            </tr>
            <!--分类下的产品-->
            <asp:Repeater ID="rptProduct" runat="server">
                <ItemTemplate>
                    <tr>
                        <td>
                            <%# DataBinder.Eval(Container.DataItem, "Course")%>
                        </td>
                        <td>
                            <%# DataBinder.Eval(Container.DataItem, "Score")%>
                        </td>
                    </tr>
                </ItemTemplate>
            </asp:Repeater>
        </ItemTemplate>
        <FooterTemplate>
            </table>
        </FooterTemplate>
    </asp:Repeater>
    </form>

根据点击Repeater上的按钮,在这行下方嵌套Repeater

 protected void rptCategories_ItemCommand(object source, RepeaterCommandEventArgs e)
        {

            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Repeater rptProduct = (Repeater)e.Item.FindControl("rptProduct");
                //找到分类Repeater关联的数据项
                DataRowView rowv = (DataRowView)e.Item.DataItem;
                var a = e.Item.Controls[0];
                //提取分类ID
                string id = e.CommandName;
                //string CategorieId = Convert.ToString(rowv["Name"]);
                //int CategorieId = Convert.ToInt32(rowv["ID"]);
                //根据分类ID查询该分类下的产品,并绑定产品Repeater
                List<Student> list = new List<Student>();
                Student stu = new Student() { Course = "语文", Score = 135 };
                list.Add(stu);
                list.Add(new Student() { Course = "数学", Score = 141 });
                //绑定嵌套数据
                rptProduct.DataSource = list;
                rptProduct.DataBind();
            }
        }

绑定原数据

protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (!IsPostBack)
                {
                    List<Student> list = new List<Student>();
                    Student stu = new Student() { ID = 100, Name = "赵六", Sex = "男", Phone = "15889898998" };
                    list.Add(stu);
                    list.Add(new Student() { ID = 102, Name = "王五", Sex = "男", Phone = "136*******8382" });
                    list.Add(new Student() { ID = 103, Name = "卡琳", Sex = "女", Phone = "138*******9083" });
                    list.Add(new Student() { ID = 105, Name = "王五", Sex = "男", Phone = "157*******7002" });

                    DataTable dt = new DataTable();
                    DataSet ds = GetDataSet("select * from profile");

                    rptCategories.DataSource = (DataTable)ds.Tables[0];
                    rptCategories.DataBind();
                }
            }
        }

时间: 2024-10-17 06:04:34

Repeater嵌套(灵活的)的相关文章

Repeater嵌套绑定Repeater

<asp:Repeater runat="server" ID="rpList" OnItemDataBound="rpList_ItemDataBound"> <ItemTemplate> <div class="catItem"> <h2> <%#Eval("DataValue")%> </h2> <div class=&qu

Repeater嵌套gridview

前台:<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1" OnItemDataBound="Repeater1_ItemDataBound">        <ItemTemplate>           id:<%#Eval("ID")%>           carid:

项目--Repeater嵌套横向显示

前台代码: <style type="text/css"> .list { list-style-type: none; text-align:center; } .list li { float: left; width: 160px; } </style> <ul class="list"> <asp:Repeater runat="server" ID="rptType">

关于Repeater嵌套绑定的问题

前台代码: <div id="firstpane" class="menu_list">                <asp:Repeater ID="rep1" runat="server" onitemdatabound="rep1_ItemDataBound">                    <ItemTemplate>                 

Repeater嵌套gridview,主从表展示

点击详细:展示详细内嵌套的gridview信息. 显示效果: 局点:0 到货时间:2014-11-020 接收人:签0 详细     局点:1 到货时间:2014-11-021 接收人:签1 详细   时间状态 接收人 2014-11-020 签0 局点:2 到货时间:2014-11-022 接收人:签2 详细     局点:3 到货时间:2014-11-023 接收人:签3 详细 <asp:UpdatePanel ID="UpdatePanel1" runat="se

repeater嵌套repeater

protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { Repeater rpWindows = e.Item.FindControl("Repeater2") as Repeater; Hid

asp.net:repeater嵌套(常用于新闻等在首页归类显示)

using System;using System.Configuration;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.Htm

Repeater嵌套

效果图 HTML页面 <asp:Repeater runat="server" ID="rptypelist" OnItemDataBound="rptypelist_ItemDataBound"> <ItemTemplate> <div class="subnav_cp02"> <span><%#Eval("ItemName") %></s

转:Repeater嵌套绑定Repeater以及内层调用外层数据

<table border="0" cellpadding="0" cellspacing="0" style="margin-bottom: 5px" width="100%"> <asp:Repeater runat="server" ID="rptypelist" OnItemDataBound="rptypelist_ItemDat