New to Telerik UI for ASP.NET AJAX? Download free 30-day trial

Programmatic Data Binding

DataSet

  • Products
    • UI for ASP.NET Ajax
      • Overview
      • Included Controls
        • Ajax for ASP.NET Ajax
        • Calendar for ASP.NET Ajax
        • Chart for ASP.NET Ajax
        • Combobox for ASP.NET Ajax
        • Docking for ASP.NET Ajax
        • Editor for ASP.NET Ajax
        • Input for ASP.NET Ajax
        • Grid for ASP.NET Ajax
        • Menu for ASP.NET Ajax
        • Panelbar for ASP.NET Ajax
        • Rotator for ASP.NET Ajax
        • Spell checker for ASP.NET Ajax
        • Splitter for ASP.NET Ajax
        • Tabstrip for ASP.NET Ajax
        • Toolbar for ASP.NET Ajax
        • Treeview for ASP.NET Ajax
        • Upload for ASP.NET Ajax
        • Window for ASP.NET Ajax
      • Why Choose
      • What's New
      • System Requirements
      • Online Demos
      • Release History
      • RoadMap
      • Documentation
      • Testimonials
      • Download Trial
      • Buy Now
    • UI for WinForms
      • Overview
      • Included Controls
        • Calendar for WinForms
        • Chart for WinForms
        • Combobox for WinFroms
        • Docking for WinForms
        • Gridview for WinForms
        • Menustrip for WinForms
        • Panelbar for WinForms
        • RibbonBar for Winforms
        • Tabstrip for WinForms
        • Toolstrip for WinForms
        • Treeview for WinForms
        • UI Elements for WinForms
      • Why Choose
      • What's New
      • System Requirements
      • Release History
      • RoadMap
      • Documentation
      • Testimonials
      • Download Trial
      • Buy Now
    • Reporting
      • Overview
      • Why Choose
      • What's New
      • System Requirements
      • Online Demos
      • Release History
      • RoadMap
      • Documentation
      • Testimonials
      • Download Trial
      • Buy Now
    • Test Studio
  • Purchase
    • Buy Now
    • License Agreement
    • Policies
    • Upgrades
    • Other ways to buy
    • Resellers
    • FAQ
    • Contact Sales
  • Support
    • Support Center
    • Requirements
    • Knowledge Base
    • Demos
    • Videos
    • Tutorials
    • Forums
    • Documentation
    • Code Library
    • Sample Projects
    • Product Skins
    • Support Options
    • FAQ
  • Community
    • White Papers
    • Learning Resources
    • Blogs
    • Telerik Labs
    • Client Spotlights
    • Telerik Points
    • MVP Program
    • Events
  • Corporate
    • Corporate Info
    • Press Center
    • Customers
    • Recent Awards
    • Careers
    • Contact Us

IEnumerable

RadNavigation fully supports binding to a wide range of datasources:

  • DataSet, DataTable, DataView
  • ASP 2.0 DataSource types including
    • Hierarchical DataSource components
    • Table-based DataSource components
    • ObjectDataSource
  • Any object that implements the IEnumerable interface 
     

Below are the properties and methods related to data binding that are available for you:

  • DataSource - Set to an instance of your data source. This is mandatory when binding the RadNavigationat runtime
  • DataSourceID - Set to the ID of your data source. This is mandatory when binding the RadNavigation declaratively
  • DataMember - If the data source is a DataSet and DataMember is set, then the RadNavigation is bound to the DataTable with the respective name in the DataSet. If DataMember is not set, the RadNavigationis bound to the first DataTable in the DataSet
  • DataFieldID - This is the field name from the data source used to uniquely identify each row. This field is required when binding to hierarchical data
  • DataFieldParentID - This is the field name from the data source used to identify the row for the parent item. This field is required when binding to hierarchical data
  • DataTextField - This is the field name from the data source that populates each item's Text property during binding
  • DataValueField - This is the field name from the data source that populates each item's Value property during binding
  • DataNavigateUrlField - This is the field name from the data source that populates each item's NavigateUrlField property during binding
  • DataBind - Call this method after you have set the aforementioned properties when binding at runtime. This method is mandatory for binding at runtime
  • MaxDataBindDepth - This property is used to determine the binding depth. If for example you want to bind only the first two levels of the menu, you should set this property to 2. The default value of the MaxDataBindDepth property is -1, which means that all items will be bound. Marking the menu instance with MaxDataBindDepth="0" will NOT bind any items.
  • AppendDataBoundItems - If you bind the menu using the DataBind method, all menu items are automatically cleared. Setting AppendDataBoundItems to True preserves the items that are already present in the menu. This lets you bind RadMenu to multiple data sources or use both unbound and bound modes.

If the data source contains fields that map to other properties of menu items or to custom attributes, you should use the ItemDataBound event to set those values:

[C#]
protected void RadMenu1_ItemDataBound(object sender,
Telerik.Web.UI.RadMenuEventArgs e)
{
e.Item.ToolTip ="Read more about " +
(string) DataBinder.Eval(e.Item.DataItem, "Text");
}


[VB]
Protected Sub RadMenu1_ItemDataBound(ByVal sender As Object, _
ByVal e As Telerik.Web.UI.RadMenuEventArgs) Handles RadMenu1.ItemDataBound
e.Item.ToolTip = "Read more about " + _
CStr(DataBinder.Eval(e.Item.DataItem, "Text"))
End Sub

  • DefaultCS.aspx
  • DefaultCS.aspx.cs
  • styles.css
<%@ Page Title="" Language="C#"  AutoEventWireup="true" CodeFile="DefaultCS.aspx.cs" Inherits="Navigation_Data_Binding_Server_side_Binding_Programmatic_Data_Binding_DefaultCS" %>

<!DOCTYPE html>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head runat="server">
    <title>Telerik ASP.NET Example</title>
    <link rel="stylesheet" type="text/css" href="styles.css" />
</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-narrow">
        <h2>DataSet</h2>
        <telerik:RadNavigation ID="RadNavigation1" runat="server" Style="z-index: 2">
        </telerik:RadNavigation>
    </div>
    <div class="demo-container size-narrow">
        <h2>IEnumerable</h2>
        <telerik:RadNavigation ID="RadNavigation2" runat="server" Style="z-index: 1">
        </telerik:RadNavigation>
    </div>

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

Support & Learning Resources

Find Assistance