700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > ASP.NET的TreeView和Menu控件分别绑定siteMap和xml文件并应用母版

ASP.NET的TreeView和Menu控件分别绑定siteMap和xml文件并应用母版

时间:2024-03-18 04:41:11

相关推荐

ASP.NET的TreeView和Menu控件分别绑定siteMap和xml文件并应用母版

目录结构

.aspx

<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server"></asp:Content><asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"><asp:Menu ID="Menu1" runat="server" DataSourceID="XmlDataSource1" Orientation="Horizontal" BackColor="#F7F6F3" DynamicHorizontalOffset="2" Font-Names="Verdana" Font-Size="Small" ForeColor="#7C6F57" StaticSubMenuIndent="10px"><DataBindings><asp:MenuItemBinding DataMember="Parent" NavigateUrlField="name" TextField="name" /><asp:MenuItemBinding DataMember="Child" NavigateUrlField="name" TextField="name" /></DataBindings><DynamicHoverStyle BackColor="#7C6F57" ForeColor="White" /><DynamicMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" /><DynamicMenuStyle BackColor="#F7F6F3" /><DynamicSelectedStyle BackColor="#5D7B9D" /><StaticHoverStyle BackColor="#7C6F57" ForeColor="White" /><StaticMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" /><StaticSelectedStyle BackColor="#5D7B9D" /></asp:Menu><asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="~/XMLFile.xml" XPath="/*/*"></asp:XmlDataSource></asp:Content><asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder2" Runat="Server"><asp:TreeView ID="TreeView2" runat="server" DataSourceID="SiteMapDataSource1" ImageSet="Arrows"><HoverNodeStyle Font-Underline="True" ForeColor="#5555DD" /><NodeStyle Font-Names="Tahoma" Font-Size="10pt" ForeColor="Black" HorizontalPadding="5px" NodeSpacing="0px" VerticalPadding="0px" /><ParentNodeStyle Font-Bold="False" /><SelectedNodeStyle Font-Underline="True" ForeColor="#5555DD" HorizontalPadding="0px" VerticalPadding="0px" /></asp:TreeView><asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" ShowStartingNode="False" /></asp:Content>

web.config

<configuration><connectionStrings><remove name="LocalSqlServer"/><add name="LocalSqlServer" connectionString="server=(localdb)\MSSQLLocalDB;database=Test;uid=;pwd=;"/></connectionStrings><system.web><compilation debug="true" targetFramework="4.5.2" /></system.web></configuration>

.sitemap

<?xml version="1.0" encoding="utf-8" ?><siteMap xmlns="/AspNet/SiteMap-File-1.0" ><siteMapNode url="" title="root" description=""><siteMapNode url="" title="学院首页" description="" /><siteMapNode url="" title="院情总览" description="classTwo"><siteMapNode url="" title="学院简介"/><siteMapNode url="" title="现任领导"/><siteMapNode url="" title="办学条件"/></siteMapNode><siteMapNode url="" title="办学成就" description="" /><siteMapNode url="" title="师资队伍" description="" /><siteMapNode url="" title="学科专业" description="" /><siteMapNode url="" title="教学管理" description="" /><siteMapNode url="" title="科学研究" description="" /><siteMapNode url="" title="合作交流" description="" /><siteMapNode url="" title="招生就业" description="" /><siteMapNode url="" title="党建思政" description="" /><siteMapNode url="" title="学生园地" description="" /></siteMapNode></siteMap>

.xml

<?xml version="1.0" encoding="utf-8" ?><Root url="" name="人工智能学院" describe=""> <Parent url="" name="学院首页" describe="" ></Parent><Parent url="" name="院情总览" describe="" ><Child url="" name="学院简介" describe=""></Child><Child url="" name="现任领导" describe=""></Child><Child url="" name="办学条件" describe=""></Child></Parent><Parent url="" name="办学成就" describe="" ></Parent><Parent url="" name="师资队伍" describe="" ></Parent><Parent url="" name="学科专业" describe="" ></Parent><Parent url="" name="教学管理" describe="" ></Parent><Parent url="" name="科学研究" describe="" ></Parent><Parent url="" name="合作交流" describe="" ></Parent><Parent url="" name="招生就业" describe="" ></Parent><Parent url="" name="党建思政" describe="" ></Parent><Parent url="" name="学生园地" describe="" ></Parent></Root>

注意:

母版拖放后,有几个控件就加几个contentPlaceHolder

添加窗体勾选选择母版页

加上/*/*启动不显示根目录

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。