页面代码

<form id="form1" runat="server">
<asp:Repeater ID="rptCategories" runat="server" OnItemCommand="rptCategories_ItemCommand">
<HeaderTemplate>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
</HeaderTemplate>
<ItemTemplate>
<!--分类名称-->
<tr>
<th>
<asp:LinkButton ID="LinkButton1" CommandName='<%#DataBinder.Eval(Container.DataItem, "ID") %>'
runat="server"><%#DataBinder.Eval(Container.DataItem, "ID")%></asp:LinkButton>
<input type="button" value="收" onclick="aa()" />
</th>
<th>
<label runat="server" id="lbl"> <%# DataBinder.Eval(Container.DataItem, "loginid")%></label>
</th>
</tr>
<!--分类下的产品-->
<asp:Repeater ID="rptProduct" runat="server">
<ItemTemplate>
<tr>
<td>
<%# DataBinder.Eval(Container.DataItem, "Course")%>
</td>
<td>
<%# DataBinder.Eval(Container.DataItem, "Score")%>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</form>

根据点击Repeater上的按钮,在这行下方嵌套Repeater

 protected void rptCategories_ItemCommand(object source, RepeaterCommandEventArgs e)
{ 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;
var a = e.Item.Controls[];
//提取分类ID
string id = e.CommandName;
//string CategorieId = Convert.ToString(rowv["Name"]);
//int CategorieId = Convert.ToInt32(rowv["ID"]);
//根据分类ID查询该分类下的产品,并绑定产品Repeater
List<Student> list = new List<Student>();
Student stu = new Student() { Course = "语文", Score = };
list.Add(stu);
list.Add(new Student() { Course = "数学", Score = });
//绑定嵌套数据
rptProduct.DataSource = list;
rptProduct.DataBind();
}
}

绑定原数据

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (!IsPostBack)
{
List<Student> list = new List<Student>();
Student stu = new Student() { ID = , Name = "赵六", Sex = "男", Phone = "" };
list.Add(stu);
list.Add(new Student() { ID = , Name = "王五", Sex = "男", Phone = "136*******8382" });
list.Add(new Student() { ID = , Name = "卡琳", Sex = "女", Phone = "138*******9083" });
list.Add(new Student() { ID = , Name = "王五", Sex = "男", Phone = "157*******7002" }); DataTable dt = new DataTable();
DataSet ds = GetDataSet("select * from profile"); rptCategories.DataSource = (DataTable)ds.Tables[];
rptCategories.DataBind();
}
}
}

Repeater嵌套(灵活的)的更多相关文章

  1. Repeater 嵌套,子级Repeater获取 父级Repeater 中的值

    第一种方法,子级Repeater中绑定父级的某个字段: <%# DataBinder.Eval((Container.NamingContainer.NamingContainer as Rep ...

  2. Repeater嵌套Repeater并取得嵌套Repeater里面的控件

    前台代码:    <asp:Repeater ID="RepeaterScene" runat="server" OnItemDataBound=&quo ...

  3. ASP.NET Repeater嵌套Repeater实现菜单加载

    在KS系统中要实现从数据库中读取界面权限文件实现菜单.界面的动态加载. 效果图: ASP.NET界面代码 <div id="menu-container"> <a ...

  4. 关于Repeater嵌套绑定的问题

    前台代码: <div id="firstpane" class="menu_list">                <asp:Repeat ...

  5. Repeater嵌套绑定Repeater

    前台Html代码 <asp:Repeater runat="server" ID="rpList" OnItemDataBound="rpLis ...

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

    <table border=" style="margin-bottom: 5px" width="100%"> <asp:Repe ...

  7. DataList与Repeater嵌套绑定

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="home.aspx.cs&quo ...

  8. asp.net:repeater嵌套(常用于新闻等在首页归类显示)

    using System;using System.Configuration;using System.Collections.Generic;using System.Linq;using Sys ...

  9. Repeater嵌套gridview

    前台:<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSour ...

随机推荐

  1. java设计模式——建造者模式

    一. 定义与类型 定义:将一个复杂对象的构建与它的表示分离,使用同样的构建过程可以创建不同的表示 用户只需制定需要建造的类型就可以得到它们,建造过程以及细节不需要知道 类型:创建型 建造者模式与工厂模 ...

  2. C#条件运算符(?:)

    一.C#条件运算符(?:) 条件运算符(?:),有时也称为三元操作符“?:”.它是根据布尔型表达式的值返回?后面的两个值中的一个.如果条件为True,则计算第一个表达式并以它的计算结果为准:如果条件为 ...

  3. vue列表过渡效果

    <transition-group></transition-group> ① 列表 <transition-group> </transition-grou ...

  4. vscode wepy 用户自定义代码片段

    VSCode wepy 自定义代码片段 { "wepy-page": { "prefix": "wepy", "body" ...

  5. Vuex的简单了解

    vuex的官网了解:https://vuex.vuejs.org/zh/guide/ 一.什么是vuex? Vuex 是一个专为 Vue.js 应用程序开发的状态管理模式.它采用集中式存储管理应用的所 ...

  6. es6展开运算符

    数组的展开合并 现在有两个数组[1, 2, 3, 4]和[5, 6, 7],想要将两个函数拼接成一个新的函数. //es5的写法 let arr1 = [1, 2, 3, 4]; let arr2 = ...

  7. 井字游戏 人机对战 java实现

    package com.ecnu.Main; /** * 主函数触发游戏 */public class MainApplication { public static void main(String ...

  8. 1046: [HAOI2007]上升序列

    Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 5822  Solved: 2071[Submit][Status][Discuss] Descript ...

  9. LIS最长上升子序列模板

    LIS n2解法: #include<iostream> #include<cstdio> using namespace std; int n,ans; ],f[]; int ...

  10. oracle 11gR2 for win7旗舰版64安装以及连接plsql和NaviCat(win64_11gR2_database) (2012-12-31-bd 写的日志迁移

    先到oracle官网http://www.oracle.com/technetwork/cn/database/enterprise-edition/downloads/index.html下载必要数 ...