实现一个可以动态改变的N层导航树
2010-12-14 22:33
531 查看
原理:
将导航树信息存储在web.config文件中,程序获取存储在web.config中导航树的信息并生成相应的导航结构。
代码:
读取web.config文件中的信息并生成相应的导航结构
web.config文件代码
将导航树信息存储在web.config文件中,程序获取存储在web.config中导航树的信息并生成相应的导航结构。
代码:
using System; using System.Configuration; using System.Collections.Generic; using System.Collections; using System.Xml; /// <summary> /// NavigateHandler 的摘要说明 /// </summary> public class NavigateHandler:IConfigurationSectionHandler { public NavigateHandler() { // // TODO: 在此处添加构造函数逻辑 // } #region IConfigurationSectionHandler 成员 public object Create(object parent, object configContext, System.Xml.XmlNode section) { XmlNodeList nodes = section.SelectNodes("link"); if (nodes.Count == 0) return null; Category normalUserRootCategory = new Category("root", "root");//创建根目录 foreach (XmlNode n in nodes) { string pname, pvalue; pname = n.Attributes["name"].Value; pvalue = n.Attributes["value"].Value; Category parentCategory = new Category(pname, pvalue);//创建主目录 normalUserRootCategory.AddChildCategory(parentCategory); XmlNodeList cnodes = n.SelectNodes("clink"); foreach (XmlNode cn in cnodes) { string cname, cvalue; cname = cn.Attributes["name"].Value; cvalue = cn.Attributes["value"].Value; Category childCategory = new Category(cname, cvalue);//创建主目录下的子目录 parentCategory.AddChildCategory(childCategory); } } return normalUserRootCategory.ChildCategoryCollection; } #endregion public static List<Category> GetCategoryList() { return (List<Category>)ConfigurationManager.GetSection("Navigate"); } }
读取web.config文件中的信息并生成相应的导航结构
<?xml version="1.0"?> <configuration> <configSections> <sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"> <sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"> <section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication"/> <sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"> <section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="Everywhere"/> <section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication"/> <section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication"/> </sectionGroup> </sectionGroup> </sectionGroup> <section name="Navigate" type="NavigateHandler,App_Code"/> </configSections> <system.web> <pages> <controls> <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/> </controls> </pages> <!-- Set compilation debug="true" to insert debugging symbols into the compiled page. Because this affects performance, set this value to true only during development. --> <compilation debug="true"> <assemblies> <add assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/> <add assembly="System.Web.Extensions.Design, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> <add assembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/> <add assembly="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/></assemblies> </compilation> <httpHandlers> <remove verb="*" path="*.asmx"/> <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/> <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/> <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/> </httpHandlers> <httpModules> <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/> </httpModules> </system.web> <system.web.extensions> <scripting> <webServices> <!-- Uncomment this line to customize maxJsonLength and add a custom converter --> <!-- <jsonSerialization maxJsonLength="500"> <converters> <add name="ConvertMe" type="Acme.SubAcme.ConvertMeTypeConverter"/> </converters> </jsonSerialization> --> <!-- Uncomment this line to enable the authentication service. Include requireSSL="true" if appropriate. --> <!-- <authenticationService enabled="true" requireSSL = "true|false"/> --> <!-- Uncomment these lines to enable the profile service. To allow profile properties to be retrieved and modified in ASP.NET AJAX applications, you need to add each property name to the readAccessProperties and writeAccessProperties attributes. --> <!-- <profileService enabled="true" readAccessProperties="propertyname1,propertyname2" writeAccessProperties="propertyname1,propertyname2" /> --> </webServices> <!-- <scriptResourceHandler enableCompression="true" enableCaching="true" /> --> </scripting> </system.web.extensions> <system.webServer> <validation validateIntegratedModeConfiguration="false"/> <modules> <add name="ScriptModule" preCondition="integratedMode" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/> </modules> <handlers> <remove name="WebServiceHandlerFactory-Integrated"/> <add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/> <add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/> <add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/> </handlers> </system.webServer> <Navigate> <link name="主栏目1" value="主栏目1"> <clink name="子栏目1" value="子栏目1"></clink> <clink name="子栏目2" value="子栏目2"></clink> <clink name="子栏目3" value="子栏目3"></clink> </link> <link name="主栏目2" value="主栏目2"> <clink name="子栏目1" value="子栏目1"></clink> <clink name="子栏目2" value="子栏目2"></clink> <clink name="子栏目3" value="子栏目3"></clink> </link> <link name="主栏目3" value="主栏目3"> <clink name="子栏目1" value="子栏目1"></clink> <clink name="子栏目2" value="子栏目2"></clink> <clink name="子栏目3" value="子栏目3"></clink> </link> <link name="主栏目4" value="主栏目4"> <clink name="子栏目1" value="子栏目1"></clink> <clink name="子栏目2" value="子栏目2"></clink> <clink name="子栏目3" value="子栏目3"></clink> </link> <link name="主栏目5" value="主栏目5"> <clink name="子栏目1" value="子栏目1"></clink> <clink name="子栏目2" value="子栏目2"></clink> <clink name="子栏目3" value="子栏目3"></clink> </link> <link name="主栏目6" value="主栏目6"> <clink name="子栏目1" value="子栏目1"></clink> <clink name="子栏目2" value="子栏目2"></clink> <clink name="子栏目3" value="子栏目3"></clink> </link> </Navigate> </configuration>
web.config文件代码
相关文章推荐
- 实现一个图片浏览器,可以改变透明度,并提供触屏细节查看功能。
- 一个利用客户端空间存储树形导航栏信息,从而实现ajax技术动态导航的雏形
- WPF: 一个可以用StoryBoard动态改变Grid行宽/列高的类
- 使用CAShapeLayer实现一个音量大小动态改变的控件
- WPF: 一个可以用StoryBoard动态改变Grid行宽/列高的类
- 自己实现的一个寻径算法的框架,具体算法采用动态库模式,可以非常方便灵活地尝试多种寻径算法
- Window.open 实现导航与打开窗口,导航到一个特定链接地址,也可以打开一个新的浏览器窗体
- 自己实现的一个寻径算法的框架,具体算法采用动态库模式,可以非常方便灵活地尝试多种寻径算法
- 拖动一个div,动态改变其td宽度的实现
- 第三百五十节,Python分布式爬虫打造搜索引擎Scrapy精讲—selenium模块是一个python操作浏览器软件的一个模块,可以实现js动态网页请求
- 一个继承于CButton的按钮控件类,实现Button背景色与文字的共存与改变,可以自行设计背景色
- 一个继承于CButton的按钮控件类,实现Button背景色与文字的共存与改变,可以自行设计背景色
- 概述 RequireJS是一个工具库,主要用于客户端的模块管理。它可以让客户端的代码分成一个个模块,实现异步或动态加载,从而提高代码的性能和可维护性。它的模块管理遵守AMD规范(Asynchronou
- Bridge 把一个抽象与其抽象操作的实现进行分离,这样,抽象与其抽象操作的实现可以独立进行改变
- josephue约瑟夫环变种 单向链表实现 (可以更改使得游戏规则动态改变)
- System.Collections.ArrayList类是一个特殊的数组。通过添加和删除元素,就可以动态改变数组的长度。
- 【远程调用框架】如何实现一个简单的RPC框架(三)优化一:利用动态代理改变用户服务调用方式
- IOS开发UI篇--使用CAShapeLayer实现一个音量大小动态改变的控件
- 原来vs2008可以改变动态端口为固定端口,这样方便提示了,哈哈
- 使用API实现的一个增加系统桌面,并且可以任意切换的小程序.