码迷,mamicode.com
首页 > 其他好文 > 详细

Repeater嵌套绑定Repeater

时间:2014-05-10 03:30:25      阅读:211      评论:0      收藏:0      [点我收藏+]

标签:blog   class   code   tar   c   int   

<asp:Repeater runat="server" ID="rpList" OnItemDataBound="rpList_ItemDataBound">
            <ItemTemplate>
                <div class="catItem">
                    <h2>
                        <%#Eval("DataValue")%> </h2>
                    <div class="catType">
                        <asp:Repeater runat="server" ID="rpListSub">
                            <ItemTemplate>
                                <a href="catgory2.aspx?id=<%#Eval("Id")%>"><%#Eval("Name")%></a>
                            </ItemTemplate>
                        </asp:Repeater>
                    </div>
                    <a href="#" class="cat-more"></a>
                </div>
            </ItemTemplate>
        </asp:Repeater>

cs文件:

protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InitData();
            }
        }
        public void InitData()
        {
            DataTable dt = SysData.GetExpertiseCategoryWeb();//web项目大类
            this.rpList.DataSource = dt;
            this.rpList.DataBind();
        }
        protected void rpList_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Repeater rep = e.Item.FindControl("rpListSub") as Repeater;//找到里层的repeater对象
                DataRowView rowv = (DataRowView)e.Item.DataItem;//找到分类Repeater关联的数据项
                int category = Convert.ToInt32(rowv["DataKey"]);//获取填充子类的id 
                rep.DataSource = SysData.GetExpertiseLevelDTByCategory(category);
                rep.DataBind();
            }
        }


Repeater嵌套绑定Repeater,布布扣,bubuko.com

Repeater嵌套绑定Repeater

标签:blog   class   code   tar   c   int   

原文地址:http://blog.csdn.net/chinaboykai/article/details/25427219

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!