閱讀651 返回首頁    go 阿裏雲 go 技術社區[雲棲]


asp.net 2.0中使用sitemapDATAsource做頁麵導航

在ASP.NET2.0中,沒有專門的頁麵導航控件,但可以使用SITEMAPdatasource配和DATALIST來實現。

SITEMAPDATASOURCE控件中,需要特別的建立一個web.sitemap的XML文件,該文件中存貯網站的結構,

比如


<?xmlversion="1.0"encoding="utf-8"?>
<siteMapxmlns="https://schemas.microsoft.com/AspNet/SiteMap-File-1.0">
<siteMapNodeurl="default.aspx?id=-1"title="首頁">
<siteMapNodeurl="default2.aspx?id=0"title="商品"/>
<siteMapNodeurl="default3.aspx?id=1"title="社區"/>
</siteMapNode>
</siteMap>



之後,在default.aspx中,寫入代碼:


<%@PageLanguage="C#"%>
<scriptrunat=server>
protectedvoidPage_Load()
{
intindex=-1;
Int32.TryParse(Request.QueryString["id"],outindex);
Tabs.SelectedIndex=index;
}
</script>
<htmlxmlns="https://www.w3.org/1999/xhtml">
<headrunat="server">
<title>UntitledPage</title>
<style>
a
{
color:#000000;
text-decoration:none;
}
.myTab
{
background:#6666ff;
padding:4px;
}
.myTabSelected
{
background:#ff00ff;
padding:4px;
}
</style>
</head>
<body>
<formrunat="server">
<div>
<table>
<asp:DataListRepeatDirection=HorizontalID="Tabs"runat="server"DataSourceID="SiteMapDataSource1">
<ItemTemplate>
<tdwidth="4"height="20"valign="top"nowrap>
<ahref='<%#Eval("Url")%>'><%#Eval("Title")%></a>
</td>
</ItemTemplate>
<SelectedItemTemplate>
<tdwidth="4"height="20"valign="top"nowrap>
<ahref='<%#Eval("Url")%>'><%#Eval("Title")%></a>
</td>
</SelectedItemTemplate>
</asp:DataList>
</table>
<asp:SiteMapDataSourceShowStartingNode=falseID="SiteMapDataSource1"runat="server"/>
</div>
</form>
</body>
</html>

就可以實現簡單的頁麵導航的效果了

最後更新:2017-04-02 00:06:36

  上一篇:go asp.net實現C#代碼加亮顯示
  下一篇:go ASP.NET與MySQL數據庫簡明圖示入門教程