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 ...
随机推荐
- python_11_guess任性玩
age_of_oldboy=56 count=0 while count<3: guess_age=int(input("guess age:")) if guess_age ...
- 安装Ubuntu桌面环境后只能Guest登录的解决办法
1.安装Ubuntu桌面环境后,登录界面只显示了Guest 2.在登录界面按住crtl+shift+F1,进入tty模式 3.输入sudo -s进入root模式 4.输入vi /etc/lightdm ...
- 【转】转自微信公众号 JavaScript 复杂判断的更优雅写法
与微信公众号看到一篇js复杂判断的文章,对我启发很大,故转到博客园以供后期不断学习并应用于项目.原文地址:https://mp.weixin.qq.com/s/ClFDRj4MnAxv1dJ5VWKS ...
- @TransactionConfiguration过时与替代写法
在使用了Spring的项目中做单元测试时,以前的标准写法是这样的: 但是在高版本的Spring框架中(Spring4.2以后),@TransactionConfiguration已经标注为过时的注解, ...
- 转载:jsonp详解
json相信大家都用的多,jsonp我就一直没有机会用到,但也经常看到,只知道是“用来跨域的”,一直不知道具体是个什么东西.今天总算搞明白了.下面一步步来搞清楚jsonp是个什么玩意. 同源策略 首先 ...
- 5- vue django restful framework 打造生鲜超市 -完成商品列表页(上)
使用Python3.6与Django2.0.2(Django-rest-framework)以及前端vue开发的前后端分离的商城网站 项目支持支付宝支付(暂不支持微信支付),支持手机短信验证码注册, ...
- 引用 Reference
在Java中,判断一个对象是否 "存活" ,都和引用有关,当一个对象没有任何的引用指向它,我们可以认为这个对象可以被GC了. 引用如何定义?Object obj = new Obj ...
- 用django实现邮件发送
settings配置 EMAIL_HOST = 'smtp.qq.com' # 如果是163换成stmp.163.com EMAIL_PORT = 465 # qq邮箱的端口 EMAIL_HOST_U ...
- CentOS下的Redis启动脚本
这是一个Shell脚本,用于管理Redis进程(启动,停止,重启),如果你在使用Redis,这个脚本可供参考. #!/bin/sh # # redis - this script starts and ...
- Linux下 导入导出数据库
1.怎么找到mysql下的bin? 1.1首先我在网上百度了一些Linux下如何导入导出数据.基本都是用mysqldump命令,但是如果没有到指定目录 下,执行这个命令是没有用的.一开始我还以为要在m ...