ASP.NET- Repeater 嵌套
我们有时候需要查找出父菜单下面全部的子菜单,然后根据子菜单的ID查找出该类别下面的全部新闻。
通常往往只知道父级菜单的ID,但不知道父级菜单下面有多少个子菜单,也不知道子菜单的ID
所以我们往往需要根据这一条SQL语句:select 子菜单ID from 表 where 父菜单ID=Id 找出全部的子菜单ID。
然后根据子菜单ID去查找出该类别下面的全部新闻
使用Repeater嵌套可以很方便实现这一点,示例如下:
前端HTML示例:
<!--使用repeater嵌套-->
<asp:Repeater runat="server" ID="repNewsList" OnItemDataBound="repNewsList_ItemDataBound">
<ItemTemplate>
<a href='newsListChild.aspx?boardId=<%#Eval("Id") %>'>更多</a><br />
<asp:Repeater runat="server" ID="repNewsChildList">
<ItemTemplate>
<%# Eval("Title") %><br />
</ItemTemplate>
</asp:Repeater>
<hr />
</ItemTemplate>
</asp:Repeater>
后端CS程序示例:
public partial class newsList : System.Web.UI.Page
{
WmwMgr db = new WmwMgr();
protected void Page_Load(object sender, EventArgs e)
{
BindData(); } /// <summary>
/// 绑定栏目数据
/// </summary>
protected void BindData(int pId)
{
repNewsList.DataSource = db.Get_ChildColumnByParentId();
repNewsList.DataBind();
} /// <summary>
/// 根据栏目数据获得新闻列表数据(嵌套Repeater)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void repNewsList_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Repeater rep = e.Item.FindControl("repNewsChildList") as Repeater;
DataRowView rowv = (DataRowView)e.Item.DataItem;
int BoardId = Convert.ToInt32(rowv["Id"]); //获取栏目Id
rep.DataSource = db.Get_NewsListByBoardId(, BoardId);
rep.DataBind();
}
} }
ASP.NET- Repeater 嵌套的更多相关文章
- ASP.NET Repeater嵌套Repeater实现菜单加载
在KS系统中要实现从数据库中读取界面权限文件实现菜单.界面的动态加载. 效果图: ASP.NET界面代码 <div id="menu-container"> <a ...
- [ASP.NET]asp.net Repeater控件的使用方法
asp.net Repeater控件的使用方法 -- : 4770人阅读 评论() 收藏 举报 asp.netserveraspdatasetdeletexhtml 今天学习了,Repeater控件 ...
- ASP.NET repeater添加序号列的方法
ASP.NET repeater添加序号列的方法 1.<itemtemplate> <tr><td> <%# Container.ItemIndex + 1% ...
- ASP.NET- 查找Repeater控件中嵌套的控件
如何在Repeater的HeaderTemplate和FooterTemplate模板中寻找控件?在Repeater的ItemTemplate模板中的控件,我们可以用Items属性来遍历行并用Find ...
- asp.net:repeater嵌套(常用于新闻等在首页归类显示)
using System;using System.Configuration;using System.Collections.Generic;using System.Linq;using Sys ...
- asp.net repeater控件操作
Repeater控件和DataList控件,可以用来一次显示一组数据项.比如,可以用它们显示一个数据表中的所有行. Repeater控件完全由模板驱动,提供了最大的灵活性,可以任意设置它的输出格式. ...
- Repeater嵌套(灵活的)
页面代码 <form id="form1" runat="server"> <asp:Repeater ID="rptCategor ...
- Repeater嵌套Repeater并取得嵌套Repeater里面的控件
前台代码: <asp:Repeater ID="RepeaterScene" runat="server" OnItemDataBound=&quo ...
- ASP.NET Repeater 控件分页
protected void Page_Load(object sender, EventArgs e) { HttpContext context = HttpContext.Current; co ...
- ASP.NET Repeater 绑定 DropDownList Calendar 选择日期
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...
随机推荐
- CSS 背景-CSS background
这里有个很好的样式学习网站:http://www.divcss5.com/rumen/r125.shtml 一.Css background背景语法 - TOP CSS背景基础知识 CSS 背 ...
- 在eclipse中将项目发布到tomcat的root目录
(1)设置项目上下文,右击项目-properties >Web Page Edit
- [jobdu]把数组排成最小的数
这道题见过,就是把相加的结果作为比较来排序就行了.注意的是comp函数里面要用const引用.而且c++里的字符串直接操作(读入和相加)也很方便. #include <iostream> ...
- new[]上面居然有一个内存计数,怪不得delete[]从来不出错
开眼界了,留个爪,以后再仔细看几遍: http://www.cnblogs.com/hazir/p/new_and_delete.html
- [Quick-x]制作新手引导高亮区域方法之一:混合模式
demo下载:https://github.com/chenquanjun/Quick-x-HighlightArea 1.混合模式 (1)首先创建一个全屏的CCRenderTexture实例 这里使 ...
- 在C++中子类继承和调用父类的构造函数方法
构造方法用来初始化类的对象,与父类的其它成员不同,它不能被子类继承(子类可以继承父类所有的成员变量和成员方法,但不继承父类的构造方法).因此,在创建子类对象时,为了初始化从父类继承来的数据成员,系统需 ...
- paip.无线路由器的无线接入WAN方式WDS设置大法
paip.无线路由器的无线接入WAN方式WDS设置大法 作者Attilax , EMAIL:1466519819@qq.com 来源:attilax的专栏 地址:http://blog.csdn. ...
- C#技术------垃圾回收机制(GC)
GC的前世与今生 虽然本文是以.NET作为目标来讲述GC,但是GC的概念并非才诞生不久.早在1958年,由鼎鼎大名的图林奖得主John McCarthy所实现的Lisp语言就已经提供了GC的功能,这是 ...
- Co-variant array conversion from x to y may cause run-time exception
http://stackoverflow.com/questions/8704332/co-variant-array-conversion-from-x-to-y-may-cause-run-tim ...
- openlayer调用geoserver发布的地图实现地图的基本功能
转自:http://starting.iteye.com/blog/1039809 主要实现的功能有放大,缩小,获取地图大小,平移,线路测量,面积测量,拉宽功能,显示标注,移除标注,画多边形获取经纬度 ...