页面代码

<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. C语言 流缓冲 Stream Buffering

    From : https://www.gnu.org/software/libc/manual/html_node/Stream-Buffering.html 译者:李秋豪 12.20 流缓冲 通常情 ...

  2. python剑指offer 顺时针打印指针

    题目描述 输入一个矩阵,按照从外向里以顺时针的顺序依次打印出每一个数字,例如,如果输入如下4 X 4矩阵: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 则依次打印出数 ...

  3. bootstrap3 文档随看

    唉 昨天看的是2,早知道就只可以看3啦,虽然整体不变,但是小改小闹的还是很多啦.产品上线是需要升级的,但是像这么改会很烦哎,有些样式名字修改,用法修改,功能修改,那让用惯了2的人还得把之前记忆清除了然 ...

  4. C# sizeof运算符

    一.C# sizeof运算符 sizeof运算符用于获取值类型的字节数. 二.示例 using System;using System.Collections.Generic;using System ...

  5. java面向对象思想2

    1.主函数是一类特殊的函数,作为程序入口,可被虚拟机调用.主函数格式是固定的.public:函数访问权限最大.static:代表函数随着类的加载已经存在.void:主函数没有具体返回值.main:不是 ...

  6. python的对数

    python的对数 首先要导入 math 模块: import math import numpy as np math.log(8,2),此为以2为底8的对数 等于 math.log2(8); 等于 ...

  7. zabbix mysql 迁移 增加分区

    1.zabbix mysql 目录清单 --basedir=/usr/local/web/mysql --datadir=/data/mysql --log-error=/data/mysql/sys ...

  8. Fight Against Traffic -简单dijkstra算法使用

    题目链接 http://codeforces.com/contest/954/problem/D 题目大意 n m s t 分别为点的个数, 边的个数,以及两个特殊的点 要求s与t间的距离在新增一条边 ...

  9. 科学计算库Numpy——随机模块

    np.random.rand() 随机生成一个[0,1)之间的浮点数. 参数表示数组的维数 np.random.randint() 生成一个随机的整数数组. 备注:生成一个5*4的二维数组,数组中的每 ...

  10. SQLite3 of python

    SQLite3 of python 一.SQLite3 数据库 SQLite3 可使用 sqlite3 模块与 Python 进行集成,一般 python 2.5 以上版本默认自带了sqlite3模块 ...