(转)在Repeater中嵌套使用Repeater

在一般的网站中浏览类别的用户控件通常都位于大多数 ASP.NET 页的左边,它使用户能够按类别快速的查找产品。最近遇到一个客户,因为在他网站上展示的产品并不多,所以要求在原有类别浏览的基础上将产品也加进去。一来更方便,二来加长了左部导航栏的长度使页面更协调。原有的分类导航栏是由Repeater实现的,现在需要在每一个分类下加入该类的商品信息,于是我想到了在原有Repeater中嵌套Repeater。实现界面如下: 

前台页面部分: 

<asp:Repeater id="rptCategories" runat="server"> 
  <HeaderTemplate> 
    <table width="100%" border="0" cellspacing="0" cellpadding="0"> 
  </HeaderTemplate> 
  <ItemTemplate> 
    <!--分类名称--> 
    <tr><th><%# DataBinder.Eval(Container.DataItem, "TypeName") %></th></tr> 
    <!--分类下的产品--> 
    <asp:Repeater id="rptProduct" runat="server"> 
      <ItemTemplate> 
        <tr><td><a href=‘ProductInfo.aspx?Id=<%# DataBinder.Eval(Container.DataItem, "ID") %>‘><%# DataBinder.Eval(Container.DataItem, "ProductName") %></a></td></tr> 
      </ItemTemplate> 
    </asp:Repeater> 
  </ItemTemplate> 
  <FooterTemplate> 
    </table> 
  </FooterTemplate> 
</asp:Repeater> 

后台代码部分(部分代码): 

//在绑定分类品名时,绑定分类下的产品 
private void rptCategories_ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e) 

    BLL.Products products =new BLL.Products(); 
    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; 
        //提取分类ID 
        int CategorieId = Convert.ToInt32(rowv["ID"]); 
        //根据分类ID查询该分类下的产品,并绑定产品Repeater 
        rptProduct.DataSource = products.GetProductsByCategorieId(CategorieId); 
        rptProduct.DataBind(); 
    } 

时间: 2024-08-02 14:01:36

(转)在Repeater中嵌套使用Repeater的相关文章

在Repeater中嵌套使用Repeater

在一般的网站中浏览类别的用户控件通常都位于大多数 ASP.NET 页的左边,它使用户能够按类别快速的查找产品.最近遇到一个客户,因为在他网站上展示的产品并不多,所以要求在原有类别浏览的基础上将产品也加进去.一来更方便,二来加长了左部导航栏的长度使页面更协调.原有的分类导航栏是由Repeater实现的,现在需要在每一个分类下加入该类的商品信息,于是我想到了在原有Repeater中嵌套Repeater.实现界面如下: 前台页面部分:  <asp:Repeater id="rptCategori

Repeater控件三层嵌套-内层Repeater添加绑定事件

用Repeater三层嵌套,最外层Repeater可以生成自己的ItemCommand事件.但接下来中间层因为是嵌套了的,所以无法在属性窗口中生成自己的事件.如果手动敲入则无效. 解决办法是需要通过编码的方式来添加事件. protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e) { //假设在第一层里面嵌套了一个名叫Repeater2 的 var temp = e.Item.FindControl

(转)Repeater中增加序号自增列

<%# Convert.ToString(Container.ItemIndex+1)%> 当Repeater空为时,提示没有数据... <FooterTemplate> <tr style="color:Red; font-size:18px;" runat="server" Visible="<%#rpt.Items.Count==0 %>" > <td colspan="8&q

Repeater嵌套绑定Repeater

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

Repeater中绑定DropDownList

效果如图: 后台代码如下 : /// <summary> /// 动态绑定Repeater中的指派下拉框 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void rptContent_ItemDataBound(object sender, RepeaterItemE

Repeater中添加按钮,点击按钮获取某一行的数据

1.添加编辑按钮和删除按钮 <asp:Repeater ID="Repeater1" runat="server" onitemcommand="Repeater1_ItemCommand"> <ItemTemplate> <table width="100%" border="1" cellpadding="0" cellspacing="0&q

手机web开发Repeater四层嵌套

最近有朋友想让我给他做个手机上页面,页面功能是显示省--市--区--门店信息,这种层级关系的数据,首先来看看效果: 我想现在的手机都是智能机了对于普通的asp.net页面开发应该没什么两样,不过最终开发下来还是有点区别: 1:首先是Safari浏览器对js的支持,和IE下面的区别. 2:页面数据的显示以及缩放等效果. 介于以上要求,我考虑使用Repeater多层嵌套来实现,下面是页面代码: <%@ Page Language="C#" AutoEventWireup="

Webfrom 生成流水号 组合查询 Repeater中单选与复选控件的使用 JS实战应用

                                         Default.aspx 网页界面 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!DOCTYPE html> <html xmlns="http://www.

关于在repeater中的checkbox实行多选和全选

今天项目中用到这一块,是一个b2b商城,业务是别人给客户留言后,客户从会员中心的留言管理中查看,用checkbox实行多选和全选后进行批量审核 首先在checkbox后加个hidden,作用见代码: string getuserid = ""; for (int i = 0; i < Repeater1.Items.Count; i++) { CheckBox cb = (CheckBox)Repeater1.Items[i].FindControl("ckBoxly&