首页 > 代码库 > Repeater嵌套绑定Repeater
Repeater嵌套绑定Repeater
<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=http://www.mamicode.com/"catgory2.aspx?id=">>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(); } }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。