关于Repeater嵌套绑定的问题

前台代码:

<div id="firstpane" class="menu_list">
                <asp:Repeater ID="rep1" runat="server" onitemdatabound="rep1_ItemDataBound">
                    <ItemTemplate>
                        <p class="menu_head" id="p<%# Eval("p_typeid")%>"><%#Eval("type_name") %></p>
                        <div class="menu_body" id="div<%# Eval("p_typeid")%>">
                           
                            <asp:Repeater ID="rep2" runat="server">
                                <ItemTemplate>
                                    <a id="a<%# Eval("p_typeid")%>" href="media.aspx?types=<%# Eval("p_typeid")%>&ptypeid=<%# Eval("p_typepid") %>">
                                        <%# Eval("type_name")%></a>
                                </ItemTemplate>
                            </asp:Repeater>
                              
                        </div>
                    </ItemTemplate>
                </asp:Repeater>
            </div>

后台代码:

protected void rep1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        //判断里层repeater处于外层repeater的哪个位置( AlternatingItemTemplate(该模板定义如何显示控件中的交替项),FooterTemplate(脚模板),

//HeaderTemplate(头模板),ItemTemplate(项模板),SeparatorTemplate(分割模板,元素能够用于描述每个记录之间的分隔符))

if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
        {
            if (e.Item.FindControl("rep2") != null)
            {
                DataRowView dv = (DataRowView)e.Item.DataItem;//找到分类Repeater关联的数据项

string pid = dv.Row["p_typeid"].ToString();//获取填充子类的id

Repeater rp = (Repeater)e.Item.FindControl("rep2");//找到里层的repeater对象

rp.DataSource = product.getP_typeById(Convert.ToInt32(pid), OleDbHelp.ConnCn);
                rp.DataBind();
            }
        }
    }

关于Repeater嵌套绑定的问题

时间: 2024-12-31 03:49:17

关于Repeater嵌套绑定的问题的相关文章

Repeater嵌套绑定Repeater

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

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

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

DataList与Repeater嵌套绑定

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="home.aspx.cs" Inherits="home" %> <body> <form id="form1" runat="server"> <asp:DataList ID="monitorTypeList"

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控件三层嵌套-内层Repeater添加绑定事件

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

repeater三级嵌套绑定

<asp:Repeater ID="rpt1" runat="server" onitemdatabound="rpt1_ItemDataBound">         <HeaderTemplate> <table width=400 cellpadding=0 cellspacing=0></HeaderTemplate>            <ItemTemplate><t

Repeater嵌套(灵活的)

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

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