asp.net 2.0 using SiteMapDataSource to do page navigation

Source: Internet
Author: User
asp.net|sitemap| page in asp.net 2.0, there is no specific page navigation control, but can be implemented using SiteMapDataSource and DataList.
SiteMapDataSource control, you need to specifically create a Web.sitemap XML file that stores the structure of the Web site,
Like what
<?xml version= "1.0" encoding= "Utf-8"?>

<sitemap xmlns= "http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >

<sitemapnode url= "Default.aspx?id=-1" title= "Home" >

<sitemapnode url= "default2.aspx?id=0" title= "Commodity"/>

<sitemapnode url= "default3.aspx?id=1" title= "community"/>

</siteMapNode>

</siteMap>
Then, in Default.aspx, write the code:
<%@ Page language= "C #"%>



<script runat=server>



protected void Page_Load ()

{

int index =-1;

Int32.TryParse (request.querystring["id"], out index);



Tabs.selectedindex = index;

}



</script>





<title>untitled page</title>

<style>

A

{

Color: #000000;

Text-decoration:none;

}



. mytab

{

Background: #6666ff;

padding:4px;

}



. mytabselected

{

Background: #ff00ff;

padding:4px;

}

</style>




<body>

<form id= "Form1" runat= "Server" >

<div>



<table>

<asp:datalist repeatdirection=horizontal id= "Tabs" runat= "Server" datasourceid= "SiteMapDataSource1" >

<ItemTemplate>

&LT;TD width= "4" height= "valign=" "Top" nowrap class= "Mytab" >

<a href= ' <%# eval ("Url")%> ' ><%# Eval ("Title")%></a>

</td>

</ItemTemplate>

<SelectedItemTemplate>

&LT;TD width= "4" height= "valign=" "Top" nowrap class= "mytabselected" >

<a href= ' <%# eval ("Url")%> ' ><%# Eval ("Title")%></a>

</td>

</SelectedItemTemplate>

</asp:DataList>

</table>

<asp:sitemapdatasource showstartingnode=false id= "SiteMapDataSource1" runat= "Server"/>

</div>

</form>

</body>



You can achieve a simple page navigation effect



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.