Telerik is a leading vendor of ASP.NET AJAX, ASP.NET MVC, Silverlight, WinForms and WPF controls and components, as well as .NET Reporting, .NET ORM , .NET CMS, Code Analysis, Mocking, Team Productivity and Automated Testing Tools. Building on its expertise in interface development and Microsoft technologies, Telerik helps customers build applications with unparalleled richness, responsiveness and interactivity. Telerik products help thousands of companies to be more productive and deliver reliable applications under budget and on time.
Version Q1 2012 released 04/11/2012
select

Menu / Declarative DataSources


  • RadMenu supports binding to various types of data sources, including declarative datasources.

    Some of the declarative data sources are inherently hierarchical. These include SiteMapDataSource and XmlDataSource. When data-bound to these types of data sources, RadMenu automatically creates the menu item hierarchy. There is no need to use the DataFieldID and DataFieldParentID properties.

    The AccessDataSource is a table-based DataSource component. It can be used to bind the menu declaratively at design time. As with binding to a DataSet, DataTable, or DataView, you can use the ID-ParentID relation to establish a hierarchy among the menu items.

    RadMenu supports binding to an ObjectDataSource as well. In addition to the standard Menu Item properties (Text, Value, Navigate Url, etc.) that can be bound to the underlying business objects, the DataFieldID and DataFieldParentID properties can be specified, too. In this way, RadMenu can create a hierarchy of Menu Items.

    Still, the business objects should provide the data needed for the RadMenu to build the hierarchy. If the ParentID property of the business objects are of nullable or reference type, then null values denote root Menu Items. In case, the ParentID property is of value type (Integer, Guid, etc.), '0'/'Guid.Empty' values denote the root Menu Items.

    For more details on the aforementioned algorithm, please read the documentation topic - Binding to object-based data sources.

Source Code

C# VB.NET
Show code in new window Demo isolation steps
  • <%@ Page Language="C#" %>

    <%@ Register TagPrefix="qsf" Namespace="Telerik.QuickStart" %>
    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
    <%@ Register TagPrefix="qsf" TagName="Header" Src="~/Common/Header.ascx" %>
    <%@ Register TagPrefix="qsf" TagName="HeadTag" Src="~/Common/HeadTag.ascx" %>
    <%@ Register TagPrefix="qsf" TagName="Footer" Src="~/Common/Footer.ascx" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <qsf:HeadTag ID="Headtag1" runat="server"></qsf:HeadTag>
        <style type="text/css">
        span.text
        {
            float: left;
            font: 13px 'Segoe UI' , Arial, sans-serif;
            color: #4888a2;
            display: block;
            width: 150px;
            padding: 2px 20px 0 0;
        }
        </style>
    </head>
    <body class="BODY">
        <form id="form1" runat="server">
            <telerik:RadScriptManager ID="ScriptManager" runat="server" />
            <qsf:Header ID="Header1" runat="server" NavigationLanguage="C#"></qsf:Header>
            <span class="text">ObjectDataSource: </span>
            <telerik:RadMenu runat="server" ID="RadMenu4" DataSourceID="ObjectDataSource1" DataTextField="Text"
                DataFieldID="ID" DataFieldParentID="ParentID" style="z-index:5"
                EnableRoundedCorners="true" EnableShadows="true" EnableTextHTMLEncoding="true">
            </telerik:RadMenu>
            <div style="clear: both">
            </div>
            <br />
            <span class="text">SiteMapDataSource: </span>
            <telerik:RadMenu runat="server" ID="RadMenu2" DataSourceID="SiteMapDataSource1" style="z-index:4"
                EnableRoundedCorners="true" EnableShadows="true" EnableTextHTMLEncoding="true">
            </telerik:RadMenu>
            <div style="clear: both">
            </div>
            <br />
            <span class="text">SqlDatasource: </span>
            <telerik:RadMenu runat="server" ID="RadMenu1" DataSourceID="SqlDataSource1" DataFieldID="id"
                DataFieldParentID="parentID" DataTextField="Text" style="z-index:3"
                EnableRoundedCorners="true" EnableShadows="true" EnableTextHTMLEncoding="true">
            </telerik:RadMenu>
            <div style="clear: both">
            </div>
            <br />
            <span class="text">XmlDataSource: </span>
            <telerik:RadMenu runat="server" ID="RadMenu3" DataSourceID="XmlDataSource1" DataTextField="Text" style="z-index:2"
                EnableRoundedCorners="true" EnableShadows="true" EnableTextHTMLEncoding="true">
            </telerik:RadMenu>
            <div style="clear: both">
            </div>
            <asp:SiteMapDataSource runat="server" ID="SiteMapDataSource1" ShowStartingNode="false" />
            <asp:SqlDataSource runat="server" ID="SqlDataSource1" ConnectionString="<%$ ConnectionStrings:TelerikConnectionString %>"
                ProviderName="System.Data.SqlClient" SelectCommand="SELECT id, text, parentId from Links" />
    <asp:XmlDataSource runat="server" ID="XmlDataSource1" DataFile="~/Menu/Examples/Programming/DeclarativeDataSources/Menu.xml"
    XPath="/Menu/Item" />

    <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetSiteData"
    TypeName="Telerik.Web.Examples.SiteDataItem"></asp:ObjectDataSource>

            <qsf:Footer ID="Footer1" runat="server"></qsf:Footer>
        </form>
    </body>
    </html>

Get more than expected!

Take your time to truly experience the power of RadControls for ASP.NET AJAX with a free 60-day trial backed up by Telerik’s unlimited dedicated support.

Download your RadControls for ASP.NET AJAX trial and jumpstart your development with the available Getting Started resources.

If you have any questions, do not hesitate to contact us at sales@telerik.com.

Copyright 2002-2012 © Telerik. All right reserved
Telerik Inc, 201 Jones Rd, Waltham, MA 02451