首页 > 其他 > 详细

Repeater嵌套绑定Repeater

时间:2014-05-10 03:30:12      阅读:444      评论:0      收藏:0      [点我收藏+]
<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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!