作为一个刚入行的IT小鸟,每天学习,是必须的!

光自学肯定是不够的!由于本人IQ比较低,经常一个小问题都会想不明白。

还好有媳妇儿的帮助,才把这个功能给实现了。

现在就在这里总结下,以示敬意。o(∩_∩)o 哈哈

分析:

前台页面,放置两个Repeater,然后在Repeater1 里面放置一个 HiddenField控件,用来获取标题。

然后在Repeater1 的ItemDataBound 事件种根据获取的标题来加载 二级标题。

数据库访问代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.OleDb;
using System.Data;/// <summary>
/// Summary description for MyDBHelper
/// </summary>
public class MyDBHelper
{public MyDBHelper(){//// TODO: Add constructor logic here//}//连接字符串public static string strConStr=@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\NoDB.mdb;"+"Persist Security Info=True";//连接数据库static OleDbConnection con;public static OleDbConnection Con{get {if(con==null){con = new OleDbConnection(strConStr);}else if(con.State== ConnectionState.Broken){con.Close();con.Open();}else if( con.State== ConnectionState.Closed){con.Open();}return con;}}//执行查询 返回Datatable#regionpublic static DataTable GetBySQL(string sql){DataTable dt = new DataTable();OleDbCommand cmd = new OleDbCommand(sql, Con);OleDbDataAdapter da = new OleDbDataAdapter(cmd);da.Fill(dt);return dt;}        #endregion//执行删除  增加  修改#region public static int ExcuteBySQL(string sql){OleDbCommand cmd = new OleDbCommand(sql, Con);int rs = cmd.ExecuteNonQuery();return rs;}#endregion
}

页面代码:


 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server"><title></title><asp:ContentPlaceHolder id="head" runat="server"></asp:ContentPlaceHolder><script src="../Script/jquery-1.3.2.min.js" language="javascript" type="text/javascript"></script><script type="text/javascript" language="javascript">$(document).ready(function () {//$("#divNavigation>dl>dt>dd").css("display","none");$("#divNavigation>dl>dt>dd").hide();$.each($("#divNavigation>dl>dt"), function () {$(this).click(function () {$("#divNavigation>dl>dt>dd").not($(this).next()).slideUp();$(this).next().slideToggle(500);});});$("ul li").mousemove(function () {$(this).css("background-color", "#ccc");}).mouseout(function () {$(this).css("background-color", "#eee");});/*  鼠标经过  */$("#divNavigation dl").each(function () {$(this).children("dt").mouseover(function () {$(this).next().css("display", "block");//$(this).next().animate({ opacity: 'show' }, 700);}).mouseout(function () {$(this).next().css("display", "none");//$(this).next().animate({ opacity: 'hide' }, 700);});/* 鼠标移动到dd上 */$(this).children("dd").mouseover(function () {$(this).css("display", "block");}).mouseout(function () {$(this).css("display", "none");});});});</script><style type="text/css">dl,dd,dt,ul,li{margin:0;padding:0;height :25px;line-height:25px; font-family:微软雅黑;font-size:12px;  }#divNavigation{width:240px;   text-align:center;}#divNavigation dl dt{border-top:1px solid #ccc;background-color:#ccc;border-bottom:1px solid #ccc;border-right:1px solid #ccc;border-left:1px solid #ccc;height:40px;line-height:40px;font-size:18px;cursor:pointer}#divNavigation ul li{list-style:none; }#divNavigation li{border-bottom:1px solid #ccc;  border-left:1px solid #ccc;border-right:1px solid #ccc;  line-height:25px;background-color:#eee;}</style>
</head>
<body><form id="form1" runat="server"><div><div style="width:1024px;height:50px;margin:0 auto; text-align:center; vertical-align:middle"><asp:Repeater ID="rptNavigation" runat="server" onitemdatabound="rptNavigation_ItemDataBound" ><ItemTemplate><div id="divNavigation" style="margin-left:1px;margin-top:10px;height:30px; float:left;"><asp:HiddenField id="hf" runat="server" Value='<%#Eval("n_name") %>'/><dl><dt><%#Eval("n_name") %></dt>                    <dd><ul style=""><asp:Repeater ID="rptS" runat="server"><ItemTemplate><li><%#Eval("n_name") %></li></ItemTemplate></asp:Repeater></ul></dd></dl>   </div></ItemTemplate></asp:Repeater>  </div><!-- 备份<div id="divNavigation" style="margin-top:10px;height:30px; float:left;"><dl><dt>基本信息管理</dt>                    <dd><ul style=""><li>Jquery</li><li>WPF</li><li>Asp.net</li><li>Winform</li></ul></dd></dl>   </div>--> <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server"></asp:ContentPlaceHolder></div></form>
</body>
</html>


CS 代码:


 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;public partial class web_web : System.Web.UI.MasterPage
{protected void Page_Load(object sender, EventArgs e){BindNavigation();}//绑定主导航public void BindNavigation(){string sql = "select * from vip_navigation where n_bid=0";rptNavigation.DataSource = MyDBHelper.GetBySQL(sql);rptNavigation.DataBind();}//项绑定事件protected void rptNavigation_ItemDataBound(object sender, RepeaterItemEventArgs e){//查找隐藏域HiddenField hfValue = (HiddenField)e.Item.FindControl("hf");//得到隐藏域的值string strName = hfValue.Value;//查找第二个RepeaterRepeater repts = (Repeater)e.Item.FindControl("rptS");//根据查找到的名称,来获取IDstring sql1 = "select n_id from vip_navigation where n_name='" + strName + "'";DataTable dt = MyDBHelper.GetBySQL(sql1);int id = 0;foreach (DataRow dr in dt.Rows){id = (int)dr["n_id"];}//根据ID获取二级导航repts.DataSource = MyDBHelper.GetBySQL("select n_name from vip_navigation where n_bid=" + id);repts.DataBind();}
}


效果:




转载于:https://www.cnblogs.com/307914070/archive/2011/02/01/1948550.html

Repeater 嵌套 Repeater相关推荐

  1. Repeater嵌套Repeater获取父级绑定项

    <%#DataBinder.Eval((Container.NamingContainer.NamingContainer as RepeaterItem).DataItem,"Com ...

  2. Repeater 嵌套 绑定数据,嵌套的Repeater无法绑定的问题

    Repeater 嵌套 绑定数据,嵌套的Repeater无法绑定的问题 今天做绑定遇到了这个么个问题,绑定的事件ItemDataBound()跟之前的并没有 改动,为什么会出现绑定失败的问题呢?要是你 ...

  3. ASP.NET中 Repeater嵌套

    ylbtech-ASP.NET-Control-Bind: Repeater嵌套 ASP.NET中 Repeater嵌套. 1.A,运行效果图返回顶部 1.B,源代码(主要代码摘要)返回顶部 /App ...

  4. Repeater嵌套总结

    Repeater嵌套使用就相当于两个for语句的组合使用. 在这组两个Reapeater的组合使用中,标示红色的代码是链接两个Repeater的纽带,主要是范围大的Repeater向范围小的Repea ...

  5. Repeater控件嵌套Repeater控件

    此篇为Repeater控件嵌套Repeater控件教程,你可以从下面相关链接下载到教程视频与源程序. 视频: 文件格式:.wmv:大小21,401KB:长度:00:16:58. 下载地址:http:/ ...

  6. 关于Repeater 嵌套梆定不明之处

    今天在网上看到一段代码,是关于Repeater 嵌套的问题,有很多的不明白的地方,希望大家能帮我把这个迷解了; 先看运行的效果: XML文件: <? xml version="1.0& ...

  7. Repeater嵌套

    效果图 HTML页面 <asp:Repeater runat="server" ID="rptypelist" OnItemDataBound=" ...

  8. 扩充NetCMS的功能:添加{TM:Repeater}{/TM:Repeater}标签

    本文档为{TM:Repeater}  {/TM:Repeater}标签的说明文档,创建的目标是打算制造一个系列文档的索引,索引的目标是关于这个标签的相关文档. 简要说明: NetCMS 1.7(以下简 ...

  9. Repeater 嵌套

    //页面 <asp:Repeater ID="parentRepeater" runat="server"> <ItemTemplate> ...

最新文章

  1. 华为堡垒机_运维堡垒机----Gateone
  2. CYQ.Data 轻量数据访问层(四) 构造数据单元列
  3. WPF/Silverlight Undo/Redo框架
  4. Spring容器创建流程(2)创建beanFactory,加载BeanDefinition
  5. android手机api等级_Android Api级别
  6. python实现编辑距离,最长公共子序列,最长公共子串
  7. 第八章节 文件操作一 (文件常用操作)
  8. ubuntu安装tim
  9. Python中文字符串,变成英文字符串
  10. CSS3实现折角效果
  11. input隐藏变显示
  12. 南财计算机专业学科评估,江苏软件工程专业大学排名:江苏哪些大学软件工程比较好?...
  13. 2022美团校招技术岗笔试全部AC_Code分享
  14. Pboot插件-包含所有Pboot插件功能
  15. 初学者都能学会的ElasticSearch入门实战《玩转ElasticSearch 2》
  16. 一个简单的自定义alert方法
  17. 2018清华计算机考研总结
  18. GPGPU-SIM(原码阅读)(流多处理器部分完成)
  19. 基恩士KV7500,基恩士触摸屏,搭载KV-SH04PL四轴运动控制模块,KV-C32XDT.
  20. 【实验】MPEG-1 Audio Layer II编码原理及编码器调试

热门文章

  1. StoryBoard 视图切换和传值
  2. CF1148F - Foo Fighters
  3. 发布开源框架到CocoaPods入坑指南
  4. org.apache.ibatis.binding.BindingException: Type interface XXX is not known to the MapperRegistry.
  5. 将MongoDB服务加入随机启动
  6. No modifications are allowed to a locked ParameterMap
  7. 内存分配管理 自定义
  8. JQuery中的事件以及动画
  9. 安卓天天酷跑脚本刷高分图文教程
  10. c++引用的自我见解