Menu - Data Source Control

ObjectDataSource

  • UI for ASP.NET Ajax
    • Grid
    • Scheduler
    • Editor
  • UI for Silverlight
    • Grid
    • Menu
    • Editor

SiteMapDataSource

  • Products
    • UI for ASP.NET AJAX
    • UI for WinForms
    • UI for WPF
    • UI for Silverlight
    • Reporting
    • Data Access
    • Sitefinity ASP.NET CMS
    • Test Studio
  • Consulting
    • On-site Training
    • Consulting Express
    • Open Classes Training
    • Online Training
    • Project Consulting
    • Telerik Webinars
  • Purchase
    • Buy Now
    • Renewals & Upgrades
    • License Agreement
    • FAQ
    • Purchase Orders
    • Contact Sales
  • Support
    • Support by Product
    • Documentation
    • Demos
    • Knowledge Base
    • Telerik Trainer
    • Videos
    • Skins
  • Community
    • Forums
    • Blogs
    • Events
    • Code Library
    • Learning Resources
    • Announcements
    • Free Products
  • Company
    • About Telerik
    • Press Center
    • Careers
    • Contact Us

SqlDatasource

  • Politics
    • CNN
    • NBC
    • ABC
  • Sports
    • US Sports
      • Baseball
      • Football
      • BasketBall
    • European Sports
      • Soccer
      • Volleyball
  • Events
    • Oscar Awards
    • MTV Movie Awards

XmlDataSource

  • File
    • New
    • Open
    • Save
    • Save As
    • Print Preview
    • Print
    • Close
  • Edit
    • Undo
    • Cut
    • Copy
    • Paste
    • Clipboard...
  • Insert
    • Break...
    • Page Numbers...
    • Date and Time...
    • Field...
    • Symbol...
    • Comment
    • Picture
    • Diagram
    • Text Box
    • Hyperlink
  • Format
    • Font
    • Paragraph...
    • Bullets and Numbering...
    • Borders and Shading...
    • Columns
    • Tabs
    • Change Case
    • Background
    • Theme
    • Frames
    • Autoformat
  • View
    • Normal
    • Web Layout
    • Print Layout
    • Task Pane
  • Tools
    • Spelling And Grammar...
    • Research...
    • Language
    • Word Count...
    • Track Changes
    • Compare And Merge Documents..

EntityDataSource

  • Politics
    • CNN
    • NBC
    • ABC
  • Sports
    • US Sports
      • Baseball
      • Football
      • BasketBall
    • European Sports
      • Soccer
      • Volleyball
  • Events
    • Oscar Awards
    • MTV Movie Awards
Isolate this demo as a stand-alone application
  • About this demo
  • C#
  • VB

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

Some of the declarative data sources are inherently hierarchical. That includes 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 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 its 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.

  • DefaultCS.aspx
  • Menu.xml
<%@ Page  %>

<!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">
    <title>Telerik ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <telerik:RadScriptManager runat="server" ID="RadScriptManager1" />
    <telerik:RadSkinManager ID="RadSkinManager1" runat="server" ShowChooser="true" />

    <div class="demo-container size-wide">
        <h2>ObjectDataSource</h2>
        <telerik:RadMenu RenderMode="Lightweight" runat="server" ID="RadMenu4" DataSourceID="ObjectDataSource1" DataTextField="Text"
            DataFieldID="ID" DataFieldParentID="ParentID" Style="z-index: 7" EnableRoundedCorners="true"
            EnableShadows="true" EnableTextHTMLEncoding="true">
        </telerik:RadMenu>
    </div>

    <div class="demo-container size-wide">
        <h2>SiteMapDataSource</h2>
        <telerik:RadMenu RenderMode="Lightweight" runat="server" ID="RadMenu2" DataSourceID="SiteMapDataSource1" Style="z-index: 6"
            EnableRoundedCorners="true" EnableShadows="true" EnableTextHTMLEncoding="true">
        </telerik:RadMenu>
    </div>

    <div class="demo-container size-wide">
        <h2>SqlDatasource</h2>
        <telerik:RadMenu RenderMode="Lightweight" runat="server" ID="RadMenu1" DataSourceID="SqlDataSource1" DataFieldID="id"
            DataFieldParentID="parentID" DataTextField="Text" Style="z-index: 5" EnableRoundedCorners="true"
            EnableShadows="true" EnableTextHTMLEncoding="true">
        </telerik:RadMenu>
    </div>

    <div class="demo-container size-wide">
        <h2>XmlDataSource</h2>
        <telerik:RadMenu RenderMode="Lightweight" runat="server" ID="RadMenu3" DataSourceID="XmlDataSource1" DataTextField="Text"
            Style="z-index: 4" EnableRoundedCorners="true" EnableShadows="true" EnableTextHTMLEncoding="true">
        </telerik:RadMenu>
    </div>

    <div class="demo-container size-wide">
        <h2>EntityDataSource</h2>
        <telerik:RadMenu RenderMode="Lightweight" runat="server" ID="RadMenu5" DataSourceID="EntityDataSource1" DataTextField="Text"
            DataFieldID="id" DataFieldParentID="parentId"
            Style="z-index: 3" EnableRoundedCorners="true" EnableShadows="true" EnableTextHTMLEncoding="true">
        </telerik:RadMenu>
    </div>

    <asp:SiteMapDataSource runat="server" ID="SiteMapDataSource1" ShowStartingNode="false"></asp:SiteMapDataSource>

    <asp:SqlDataSource runat="server" ID="SqlDataSource1" ConnectionString="<%$ ConnectionStrings:TelerikConnectionString %>"
        ProviderName="System.Data.SqlClient" SelectCommand="SELECT id, text, parentId from Links"></asp:SqlDataSource>

    <asp:XmlDataSource runat="server" ID="XmlDataSource1" DataFile="~/Menu/Examples/Programming/DeclarativeDataSources/Menu.xml"
        XPath="/Menu/Item"></asp:XmlDataSource>

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

    <asp:EntityDataSource runat="server" ID="EntityDataSource1" ConnectionString="name=TelerikReadWriteEntities"
        DefaultContainerName="TelerikReadWriteEntities" EntitySetName="Links">
    </asp:EntityDataSource>

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

Find Assistance

Help Us Improve

Was this example helpful?