页面代码

<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. 文件系统 - Linux 支持的文件系统类型

    NAME 文件系统 - Linux 支持的文件系统类型:minix, ext, ext2, xia, msdos, umsdos, vfat, proc, nfs, iso9660, hpfs, sy ...

  2. 多线程:InterlockedIncrement

    1.InterlockedIncrement保护多线程中操作的整数. #include <stdio.h> #include <windows.h> volatile long ...

  3. CUDA:Supercomputing for the Masses (用于大量数据的超级计算)-第三节

    原文链接 第三节:错误处理和全局内存性能局限 恭喜!通过对CUDA(Compute Unified DeviceArchitecture,即计算统一设备架构的首字母缩写)系列文章第一节和第二节,您现在 ...

  4. 51nod——1640 天气晴朗的魔法 有边权限制的最大生成树

    好好读题嗷:“所以我们要求阵中的魔法链的魔力值最大值尽可能的小,与此同时,魔力值之和要尽可能的大.” 第一条件是生成树的最大边权更小,第二条件是在最大边权的限制下搞一个最大生成树. 至于最大生成树,如 ...

  5. 当GetWindowText获取不到标题时可以用SendMessage

    GetWindowText所有父窗口标题基本可以获取到, 但是当获取父窗口下的子窗口控件标题文本时有时候就没那么好用了, 这个时候可以通过SendMessage发送消息来获取,也很简单,C/C++代码 ...

  6. [BZOJ] 3875: [Ahoi2014&Jsoi2014]骑士游戏

    设\(f[x]\)为彻底杀死\(x\)号怪兽的代价 有转移方程 \[ f[x]=min\{k[x],s[x]+\sum f[v]\} \] 其中\(v\)是\(x\)通过普通攻击分裂出的小怪兽 这个东 ...

  7. MySQL - FULL JOIN

    SQL FULL JOIN 关键字 只要其中某个表存在匹配,FULL JOIN 关键字就会返回行. FULL JOIN 关键字语法 SELECT column_name(s) FROM table_n ...

  8. kubernetes搭建dashboard报错

    warningconfigmaps is forbidden: User "system:serviceaccount:kube-system:kubernetes-dashboard&qu ...

  9. git上传自己的代码

    感谢这个哥们的博客,不过里面有些错误. http://www.cnblogs.com/ruofengzhishang/p/3842587.html 下面是我自己的实践成功的: 这篇文章写得是windo ...

  10. TCP/IP网络编程之域名及网络地址

    域名系统 DNS是对IP地址和域名进行互相转换的系统,其核心是DNS服务器.提供网络服务的服务端也是通过IP地址来区分的,但由于IP地址难于记忆,因此通过容易记忆并表述的域名来取代IP地址 在浏览器地 ...