ASP.NET2.0 menu控件制作下拉式导航菜单

步骤:

1. XML文件。这里用XML文档:slivermenu.xml描述了菜单的具体内容。如 

xml version="1.0" encoding="utf-8"  ?>
< items >
  
< menuitem  navigateurl ="http //dotnet. x.cc/"  text ="网站首页" >
    
< menuitem  navigateurl ="http //dotnet. x.cc/ShowList. x?id=1"  text ="新闻通知" >
      
< menuitem  navigateurl ="Classical. x"  text ="新闻1" />
      
< menuitem  navigateurl ="Rock. x"  text ="新闻2" >
        
< menuitem  navigateurl ="Classical. x"  text ="最新新闻2.1" />
        
< menuitem  navigateurl ="Classical. x"  text ="最新新闻2.2" />
      
menuitem >
    
menuitem >
    
< menuitem  navigateurl ="Movies. x"  text ="学科介绍" >
      
< menuitem  navigateurl ="Action. x"  text ="通知1" />
      
< menuitem  navigateurl ="Drama. x"  text ="通知2" />
      
< menuitem  navigateurl ="Musical. x"  text ="通知3" />
    
menuitem >
    
< menuitem  navigateurl =""  text ="导师风采" >

    
menuitem >
    
< menuitem  navigateurl =""  text ="党团工作" >
      
    
menuitem >
    
< menuitem  navigateurl =""  text ="招生就业" >

    
menuitem >
    
< menuitem  navigateurl =""  text ="研究生会" >

    
menuitem >
    
< menuitem  navigateurl =""  text ="毕业生风采" >

    
menuitem >
    
< menuitem  navigateurl =""  text ="请假系统" >

    
menuitem >
    
< menuitem  navigateurl =""  text ="下载专栏" >

    
menuitem >
    
< menuitem  navigateurl =""  text ="BBS" >

    
menuitem >
  
menuitem >
items >

2.添加XMLDataSource控件,配置数据源:slivermenu.xml

3.添加Menu控件。配置数据源XMLDataSource1.

4.数据绑定。在Menu1的属性面板里,选择Databinding,点选menuitem,添加到“所选数据绑定里”在右侧的对话框的数据绑定中,TextField选text,NavigatrURLField选Navigatrurl。点“确定”。

5.在Menu控件属性面板中选择Orientation:Horizontal。

ok,打完收工。具体代码如下:

 

<% @ Page Language = " C# "  AutoEventWireup = " true "  CodeFile = " slivermenu.aspx.cs "  Inherits = " slivermenu "   %>

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 > slivermenu title >
head >
< body >
    
< form id = " form1 "  runat = " server " >
        
& nbsp;
        
< asp:XmlDataSource ID = " XmlDataSource1 "  runat = " server "  DataFile = " ~/App_Data/staticmenu.xml "
            XPath
= " items/menuitem "  OnTransforming = " XmlDataSource1_Transforming " > asp:XmlDataSource >
        
< asp:Menu ID = " Menu1 "  runat = " server "  DataSourceID = " XmlDataSource1 "  DynamicHorizontalOffset = " 17 "
            Font
- Bold = " True "  Font - Size = " Small "  MaximumDynamicDisplayLevels = " 2 "  Orientation = " Horizontal "
            StaticDisplayLevels
= " 2 "  Style = " position: relative " >
            
< DataBindings >
                
< asp:MenuItemBinding DataMember = " menuitem "  NavigateUrlField = " navigateurl "  TextField = " text "   />
            
DataBindings >
        
asp:Menu >
   
form >
body >
html >

 

 

你可能感兴趣的:(ASP.NET)