我们有时候需要查找出父菜单下面全部的子菜单,然后根据子菜单的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 嵌套的更多相关文章

  1. ASP.NET Repeater嵌套Repeater实现菜单加载

    在KS系统中要实现从数据库中读取界面权限文件实现菜单.界面的动态加载. 效果图: ASP.NET界面代码 <div id="menu-container"> <a ...

  2. [ASP.NET]asp.net Repeater控件的使用方法

    asp.net Repeater控件的使用方法 -- : 4770人阅读 评论() 收藏 举报 asp.netserveraspdatasetdeletexhtml 今天学习了,Repeater控件 ...

  3. ASP.NET repeater添加序号列的方法

    ASP.NET repeater添加序号列的方法 1.<itemtemplate> <tr><td> <%# Container.ItemIndex + 1% ...

  4. ASP.NET- 查找Repeater控件中嵌套的控件

    如何在Repeater的HeaderTemplate和FooterTemplate模板中寻找控件?在Repeater的ItemTemplate模板中的控件,我们可以用Items属性来遍历行并用Find ...

  5. asp.net:repeater嵌套(常用于新闻等在首页归类显示)

    using System;using System.Configuration;using System.Collections.Generic;using System.Linq;using Sys ...

  6. asp.net repeater控件操作

    Repeater控件和DataList控件,可以用来一次显示一组数据项.比如,可以用它们显示一个数据表中的所有行. Repeater控件完全由模板驱动,提供了最大的灵活性,可以任意设置它的输出格式. ...

  7. Repeater嵌套(灵活的)

    页面代码 <form id="form1" runat="server"> <asp:Repeater ID="rptCategor ...

  8. Repeater嵌套Repeater并取得嵌套Repeater里面的控件

    前台代码:    <asp:Repeater ID="RepeaterScene" runat="server" OnItemDataBound=&quo ...

  9. ASP.NET Repeater 控件分页

    protected void Page_Load(object sender, EventArgs e) { HttpContext context = HttpContext.Current; co ...

  10. ASP.NET Repeater 绑定 DropDownList Calendar 选择日期

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...

随机推荐

  1. pptpvpn记录用户登录和流量信息

    这个问题困扰了我很久,终于在pppd的man文档里,发现了踪迹.在man中的SCRIPTS下有一系列的参数,其中PEERNAME就是登陆的用户名,并且在/etc/ppp/ip-up和/etc/ppp/ ...

  2. BZOJ 3715: [PA2014]Lustra

    Description Byteasar公司专门外包生产带有镜子的衣柜.刚刚举行的招标会上,有n个工厂参加竞标.所有镜子都是长方形的,每个工厂能够制造的镜子都有其各自的最大.最小宽度和最大.最小高度. ...

  3. How Does #DeepDream Work?

    How Does #DeepDream Work? Do neural networks hallucinate of electronic dogs? If you’ve been browsing ...

  4. 机器学习算法与Python实践之(二)支持向量机(SVM)初级

    机器学习算法与Python实践之(二)支持向量机(SVM)初级 机器学习算法与Python实践之(二)支持向量机(SVM)初级 zouxy09@qq.com http://blog.csdn.net/ ...

  5. sublime text 2 前端编码神器-快捷键与使用技巧介绍

    介绍网址:http://www.xuanfengge.com/sublime-text-2-artifact.html

  6. ANGULAR 2 FOR REACT DEVELOPERS

    Now that Angular 2 is in beta, the time has come for us to drop everything and learn something new, ...

  7. WebKit Web Inspector增加覆盖率分析和类型推断功能

    WebKit中的Web Inspector(Web检查器)主要用于查看页面源代码.实时DOM层次结构.脚本调试.数据收集等,日前增加了两个十分有用的新功能:覆盖率分析和类型推断.覆盖率分析工具能够可视 ...

  8. Codeforces Round #239 (Div. 2) C. Triangle

    time limit per test:1 secondmemory limit per test:256 megabytesinput:standard inputoutput:standard o ...

  9. NRE

    NRE是Non-Recurring Engineering的缩写,NRE费用即一次性工程费用,是指集成电路生产成本中非经常性发生的开支,明确地说就是新的集成电路产品的研制开发费·新产品开发过程中的设计 ...

  10. Spring事务管理--多个ORM框架在使用时的情况分析

    公司的项目已经接近尾声了,总结一下项目中用到的技术,我发现项目中的有些东西还是挺模糊的,只是知道这么用就行了.并不清楚其中的原理.由于公司的项目比较老,是7年前的一个项目了,中间一直有人在维护,也是在 ...