Repeater嵌套(灵活的)
页面代码
<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嵌套(灵活的)的更多相关文章
- Repeater 嵌套,子级Repeater获取 父级Repeater 中的值
第一种方法,子级Repeater中绑定父级的某个字段: <%# DataBinder.Eval((Container.NamingContainer.NamingContainer as Rep ...
- Repeater嵌套Repeater并取得嵌套Repeater里面的控件
前台代码: <asp:Repeater ID="RepeaterScene" runat="server" OnItemDataBound=&quo ...
- ASP.NET Repeater嵌套Repeater实现菜单加载
在KS系统中要实现从数据库中读取界面权限文件实现菜单.界面的动态加载. 效果图: ASP.NET界面代码 <div id="menu-container"> <a ...
- 关于Repeater嵌套绑定的问题
前台代码: <div id="firstpane" class="menu_list"> <asp:Repeat ...
- Repeater嵌套绑定Repeater
前台Html代码 <asp:Repeater runat="server" ID="rpList" OnItemDataBound="rpLis ...
- 转:Repeater嵌套绑定Repeater以及内层调用外层数据
<table border=" style="margin-bottom: 5px" width="100%"> <asp:Repe ...
- DataList与Repeater嵌套绑定
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="home.aspx.cs&quo ...
- asp.net:repeater嵌套(常用于新闻等在首页归类显示)
using System;using System.Configuration;using System.Collections.Generic;using System.Linq;using Sys ...
- Repeater嵌套gridview
前台:<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSour ...
随机推荐
- mac 远程桌面提示: 证书或相关链无效
左上角 RDC -->首选项-->安全性-->即使验证失败,也始终链接
- 剑指Offer的学习笔记(C#篇)-- 和为S的连续正数序列
题目描述 小明很喜欢数学,有一天他在做数学作业时,要求计算出9~16的和,他马上就写出了正确答案是100.但是他并不满足于此,他在想究竟有多少种连续的正数序列的和为100(至少包括两个数).没多久,他 ...
- python内置函数map/reduce/filter
python有几个内置的函数很有意 思:map/filter/reduce,都是对一个集合进行处理,filter很容易理解用于过滤,map用于映射,reduce用于归并. 是python列表方法的三架 ...
- AngularJS最佳实践
1.依赖注入不要用推断式 2.双向绑定的变量设置成$scope下的一个对象的属性 3.多个控制器之间的通信尽量使用service实现,不要使用全局变量或者$rootScope 4.尽量不在控制器中操作 ...
- python的对数
python的对数 首先要导入 math 模块: import math import numpy as np math.log(8,2),此为以2为底8的对数 等于 math.log2(8); 等于 ...
- C/C++ 程序基础 (一)基本语法
域操作符: C++ 支持通过域操作符访问全局变量,C不支持(识别为重定义) ++i和i++的效率分析: 内置类型,无区别 自定义数据类型,++i可以返回引用,i++只能返回对象值(拷贝开销) 浮点数与 ...
- 记录一些 FileZillaClient 的基本连接操作
本地主机:Window 10 FileZilla版本:3.39.0 64位 远程主机:CentOS 6.4 需安装FTP服务 小提示:查看CentOS版本命令 # cat /etc/issue Fil ...
- nginx修改nginx.conf配置可以https访问
修改nginx.conf,参照如下更改配置server { listen 443; server_name abc.com; // 访问域名 ssl on; root /var/www/bjubi.c ...
- java的重写(Override) (2013-10-11-163 写的日志迁移
/* *说明方法的重写(又称方法的覆盖)子类并不想原封不动地继承父类的方法,而是想作一定的修改 */ package czbk.jxy.study; /** * @author Archon * @d ...
- day 52 Django基础一之web框架的本质
Django基础一之web框架的本质 django第一天 本节目录 一 web框架的本质及自定义web框架 二 模板渲染JinJa2 三 MVC和MTV框架 四 Django的下载安装 五 基于D ...