站点导航功能+母版页实现统一风格的站点

站点导航功能+母版页实现统一风格的站点
效果如图:

1、新建网站...
2、“网站”--“添加新项”--添加一个名为“web.sitemap”的xml文件,代码如下:

 

<?xml version="1.0" encoding="utf-8" ?>
<siteMap>
   
<siteMapNode title="Home" description="Home" url="default.aspx" >
      
<siteMapNode title="Products" description="Our products" 
          url
="Products.aspx">
          
<siteMapNode title="Hardware" description="Hardware choices"
               url
="Hardware.aspx" />
          
<siteMapNode title="Software" description="Software choices" 
               url
="Software.aspx" />
      
</siteMapNode>
      
<siteMapNode title="Services" description="Services we offer" 
         url
="Services.aspx">
         
<siteMapNode title="Training" description="Training classes" 
             url
="Training.aspx" />
         
<siteMapNode title="Consulting" description="Consulting services" 
             url
="Consulting.aspx"/>
         
<siteMapNode title="Support" 
             description
="Supports plans" 
             url
="Support.aspx" 
             pagetitle
="Here's a custom page title"
         
/>
      
</siteMapNode>
      
<siteMapNode title="Admin" 
          description
="For admins only" 
          url
="admin.aspx" 
          roles
="SiteAdmin,SuperUser"
      
/>
   
</siteMapNode>
</siteMap>


******************
3、“网站”--“添加新项”--添加一个名为“master1.master”的母版页,代码如下:

<%@ master language="C#" %>

<script runat="server">
</script>

<html>
<head id="Head1" runat="server">
    
<title>Untitled Page</title>
</head>
<body>
    
<form id="Form1" runat="server">
        
<table id="Table1" cellspacing="1" cellpadding="1" width="100%" border="1">
            
<tr>
                
<td colspan="2">
                    
<h1>My Little Company</h1>
                
</td>
            
</tr>
            
<tr>
                
<td colspan="2">
                    
<asp:datalist id="DataList1" runat="server" repeatdirection="Horizontal" datasourceid="SiteMapDataSource2">
                        
<itemtemplate>
                            
<asp:hyperlink id="HyperLink1" runat="server" navigateurl='<%# DataBinder.Eval(Container.DataItem, "url") %>' text='<%# DataBinder.Eval(Container.DataItem, "title"%>'>
                            
</asp:hyperlink>
                        
</itemtemplate>
                    
</asp:datalist>
                    
<asp:sitemapdatasource id="SiteMapDataSource2" runat="server" >
                    
</asp:sitemapdatasource>
                    
<br />
                    You are here:
                    
<asp:sitemappath id="Node" runat="server" PathSeparator=">">
                    
</asp:sitemappath>
                
</td>
            
</tr>
            
<tr>
                
<td valign="top">
                    
<asp:treeview id="TreeView1" runat="server" font-underline="False" datasourceid="SiteMapDataSource1"  font-names="Verdana" font-size="8pt" font-italic="False" font-bold="False" imageset="MSDN" forecolor="#000000" nodeindent="16" backcolor="#EEEEEE">
                        
<selectednodestyle verticalpadding="1" bordercolor="#999999" horizontalpadding="3"
                            backcolor
="#FFFFFF" font-underline="False" font-italic="False" font-bold="False"
                            borderwidth
="1px" borderstyle="Solid">
                        
</selectednodestyle>
                        
<hovernodestyle  bordercolor="#999999"  backcolor="#C7C7C7"
                            font-underline
="True" font-italic="False" font-bold="False" borderwidth="1px"
                            borderstyle
="Solid">
                        
</hovernodestyle>
                        
<parentnodestyle font-underline="False" font-italic="False" font-bold="False">
                        
</parentnodestyle>
                        
<leafnodestyle font-underline="False" font-italic="False" font-bold="False">
                        
</leafnodestyle>
                        
<nodestyle font-underline="False" forecolor="#000000" verticalpadding="2" nodespacing="1" horizontalpadding="4" font-names="Verdana" font-size="8pt" font-italic="False" font-bold="False">
                        
</nodestyle>
                        
<rootnodestyle font-underline="False" font-italic="False" font-bold="False">
                        
</rootnodestyle>
                    
</asp:treeview>
                    
<asp:sitemapdatasource id="SiteMapDataSource1" runat="server" >
                    
</asp:sitemapdatasource>
                
</td>
                
<td>
                    
<asp:contentplaceholder id="ContentPlaceHolder1" runat="server">
                    
</asp:contentplaceholder>
                
</td>
            
</tr>
            
<tr>
                
<td>
                
</td>
                
<td>
                
</td>
            
</tr>
        
</table>
    
</form>
</body>
</html>

 


如图:

4、“网站”--“添加新项”--依次添加admin.aspx、Consulting.aspx、Hardware.aspx、Products.aspx、
Services.aspx、Software.aspx、Support.aspx、Training.aspx
并“选择母版页"把master1.master指定为它们的母版.(这几个网页可以自己在ContentPlaceHolder1添加控件或文本上去)


5、调试一下看看,我们可以根据自己的需要对母版页底表格进行修改、也可以添加几ContentPlaceHolder进去的。

参考:
《asp.net 2.0 大揭密》第五章集成站点导航功能
按照书本做会提示错误:
"The file web.sitemap required by XmlSiteMapProvider does not exist. "!
然后把app.sitemap改为web.sitemap就可以了。

注意:DataList1的PathSeparator=">"我们可以改为别的。 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值