Поделиться через


SiteMapDataSource Web Server Control Declarative Syntax

Provides a data source control that Web server controls and other controls can use to bind to hierarchical site map data.

<asp:SiteMapDataSource
    EnableTheming="True|False"
    EnableViewState="True|False"
    ID="string"
    OnDataBinding="DataBinding event handler"
    OnDisposed="Disposed event handler"
    OnInit="Init event handler"
    OnLoad="Load event handler"
    OnPreRender="PreRender event handler"
    OnUnload="Unload event handler"
    runat="server"
    ShowStartingNode="True|False"
    SiteMapProvider="string"
    SkinID="string"
    StartFromCurrentNode="True|False"
    StartingNodeOffset="integer"
    StartingNodeUrl="uri"
    Visible="True|False"
/>

Remarks

The SiteMapDataSource control is a data source to the site map data that is stored by the site map providers that are configured for your site. The SiteMapDataSource enables Web server controls that are not specifically site navigation controls, such as the TreeView, Menu, and DropDownList controls, to bind to hierarchical site map data. You can use these Web server controls to display a site map as a table of contents or to actively navigate a site. Alternatively, you can use the SiteMapPath control, which is designed specifically as a site navigation control and therefore does not need an instance of the SiteMapDataSource control.

For more information on the SiteMapDataSource control and navigation controls, see Navigation ASP.NET Controls.

Example

The following code example demonstrates how to declaratively bind a TreeView control to a site map using a SiteMapDataSource control. The site map data is retrieved beginning at the root node level.

<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
        <form id="form1" runat="server">
            <asp:SiteMapDataSource
                id="SiteMapDataSource1"
                runat="server" />

            <asp:TreeView
                id="TreeView1"
                runat="server"
                DataSourceID="SiteMapDataSource1">
            </asp:TreeView>

        </form>
    </body>
</html>
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
        <form id="form1" runat="server">
            <asp:SiteMapDataSource
                id="SiteMapDataSource1"
                runat="server" />

            <asp:TreeView
                id="TreeView1"
                runat="server"
                DataSourceID="SiteMapDataSource1">
            </asp:TreeView>

        </form>
    </body>
</html>
<%@ Page Language="VJ#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
        <form id="form1" runat="server">
            <asp:SiteMapDataSource
                id="SiteMapDataSource1"
                runat="server">
            </asp:SiteMapDataSource>

            <asp:TreeView
                id="TreeView1"
                runat="server"
                DataSourceID="SiteMapDataSource1">
            </asp:TreeView>

        </form>
    </body>
</html>

See Also

Reference

SiteMapDataSource

Other Resources

Navigation ASP.NET Controls