Use sitemapdatasource in Asp.net 2.0 for page navigation

Source: Internet
Author: User

There is no special page navigation control in ASP. NET 2.0, but it can be implemented using sitemapdatasource configuration and datalist.
In the sitemapdatasource control, you must create a web. sitemap XML file that stores the website structure,
For example
<? 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 =" Homepage ">

<Sitemapnode url = "default2.aspx? Id = 0 "Title =" commodity "/>

<Sitemapnode url = "default3.aspx? Id = 1 "Title ="Community"/>

</Sitemapnode>

</Sitemap>
Then, in default. aspx, writeCode:
<% @ Page Language = "C #" %>

 

<SCRIPT runat = Server>

 

Protected void page_load ()

{

Int Index =-1;

Int32.tryparse (request. querystring ["ID"], out index );

 

Tabs. selectedindex = index;

}

</SCRIPT>

 

<HTML xmlns = "http://www.w3.org/1999/xhtml">

<Head id = "head1" runat = "server">

<Title> untitled page </title>

<Style>

A

{

Color: #000000;

Text-Decoration: none;

}

. Mytab

{

Background: # 6666ff;

Padding: 4px;

}

 

. Mytabselected

{

Background: # ff00ff;

Padding: 4px;

}

</Style>

 

</Head>

<Body>

<Form ID = "form1" runat = "server">

<Div>

<Table>

<Asp: datalist repeatdirection = horizontal id = "tabs" runat = "server" performanceid = "sitemapperformance1">

<Itemtemplate>

<TD width = "4" Height = "20" valign = "TOP" nowrap class = "mytab">

<A href = '<% # eval ("url") %>'> <% # eval ("title") %> </a>

</TD>

</Itemtemplate>

<Selecteditemtemplate>

<TD width = "4" Height = "20" 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>

</Html>

You can achieve the effect of simple page navigation.


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.