ASP. NET-how to: display site map data in a non-hierarchical Web Server Control

Source: Internet
Author: User

In essence, site map data is layered, which means that each node can contain zero or multiple subnodes. The Treeview and menu controls are used to process hierarchical data. However, you can also bind site map data to non-hierarchical controls, such as dropdownlist, checkboxlist, and other controls that display data in linear or flat format.

Note: Only the sitemappath control and the control that supports the inavigateuidata interface render the site map node as a link.

 

Example

The following code example uses the dropdownlist control to display site map data from the Web. sitemap file.

When the client selects an item from the drop-down list, the browser will be redirected to the selected page. This is achieved by calling the Redirect method in the onselectedindexchanged event handler.

If you place this sample code on the master page, the startfromcurrentnode attribute in the sitemapdatasource control ensures that a site map is always displayed in the drop-down list, starting from the page currently being executed.

<% @ Page Language = "C #" autoeventwireup = "true" %>

 

<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

 

<SCRIPT runat = "server">

Void _ onselectedindexchanged (Object sender, eventargs E)

{

Response. Redirect (dropdownlist1.selecteditem. value );

}

</SCRIPT>

 

<HTML>

<Head runat = "server">

<Title> dropdownlist bound to sitemapdatasource </title>

</Head>

<Body>

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

<Div>

<Asp: sitemapdatasource id = "sitemapdatasource1" runat = "server"

Startfromcurrentnode = "true"

Showstartingnode = "false"/>

<Asp: dropdownlist id = "dropdownlist1" runat = "server"

Performanceid = "sitemapdatasource1"

Autopostback = "true"

Datatextfield = "title"

Datavaluefield = "url"

Onselectedindexchanged = "_ onselectedindexchanged">

</ASP: dropdownlist>

</Div>

</Form>

</Body>

</Html>

If the page does not contain any child nodes, the drop-down list will be empty. If the client selects an item but does not set the corresponding URL attribute in the web. sitemap file, the client will be redirected to the home page of the application.

 

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.