Repeater嵌套

效果图

HTML页面

 <asp:Repeater runat="server" ID="rptypelist" OnItemDataBound="rptypelist_ItemDataBound">
      <ItemTemplate>
          <div class="subnav_cp02">
              <span><%#Eval("ItemName") %></span>
                 <dl>
                     <dd>
                        <asp:Repeater runat="server" ID="rpquestionlist">
                           <ItemTemplate>
                              <a href="/ProductList.aspx?ID=<%#Eval("Id")%>"><%#Eval("ItemName") %></a>
                           </ItemTemplate>
                         </asp:Repeater>
                       </dd>
                   </dl>
            </div>
      </ItemTemplate>
  </asp:Repeater>

引用空间

using System.Web.UI.WebControls;
using System.Data;

.cs文件

  public void RpTypeBind()
  {         //数据源绑定的是一张表
     this.rptypelist.DataSource = Letao.BLL.ProductCategory.GetDataSet(0).Tables[0];
     this.rptypelist.DataBind();
  }

    //在绑定分类品名时,绑定分类下的产品
    public void rptypelist_ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            Repeater rptProduct = (Repeater)e.Item.FindControl("rpquestionlist");
            //找到分类Repeater关联的数据项
            DataRowView rowv = (DataRowView)e.Item.DataItem;
            //提取分类ID
            int CategorieId = Convert.ToInt32(rowv["ID"]);
            //根据分类ID查询该分类下的产品,并绑定产品Repeater
            rptProduct.DataSource =Letao.BLL.ProductCategory.GetDataSet(CategorieId).Tables[0];
            rptProduct.DataBind();
        }
    }

备注:绑定大类时返回的是表结构

SQLSERVER类库

 /// <summary>
        /// 根据父ID取得类别列表
        /// </summary>
        /// <param name="pItemId">父ID</param>
        /// <returns></returns>
        public DataSet GetDataSet(int ParentId)
        {
            string sql = "select * from ProductCategory where ParentId=" + ParentId + " and ItemName<>‘‘ order by SortValue asc,id asc";
            return DBUtility.DbHelperSQL.ExecuteDataSet(ConnString.connReadonly, CommandType.Text, sql, null);
        }

根据父ID取得类别列表

数据库结构

时间: 2024-10-05 05:31:32

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嵌套(灵活的)

页面代码 <form id="form1" runat="server"> <asp:Repeater ID="rptCategories" runat="server" OnItemCommand="rptCategories_ItemCommand"> <HeaderTemplate> <table width="100%" border=&

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嵌套绑定Repeater以及内层调用外层数据

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