DropDownList - Server-side Data Binding

ObjectDataSource

Select Movie

SqlDataSource

Select Customer

XmlDataSource

Select City

Entity DataSouce

Select Customer

Isolate this demo as a stand-alone application
  • About this demo
  • C#
  • VB

RadDropDownList supports binding to various data source controls. This demo demonstrates how to bind the control to various ASP.NET DataSource components.

  • DefaultCS.aspx
  • DefaultCS.aspx.cs
  • dropdownlist.xml
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DefaultCS.aspx.cs" Inherits="DropDownList.Examples.DeclarativeDataSources.DefaultCS" %>

<!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" />

    <telerik:RadAjaxPanel runat="server" ID="RadAjaxPanel1">

        <div class="demo-container size-thin">
            <h2>ObjectDataSource</h2>
            <telerik:RadDropDownList RenderMode="Lightweight" ID="RadDropDownList1" runat="server"  Width="220px"
                DataSourceID="ObjectDataSource1" DataTextField="Title" DataValueField="Id" DefaultMessage="Select Movie">
            </telerik:RadDropDownList>
            <telerik:RadButton RenderMode="Lightweight" runat="server" Text="Select" ID="Button1"  OnClick="Button1_Click" />
            <p>
                <asp:Label runat="server" ID="Label1" />
            </p>
        </div>
        <div class="demo-container size-thin">
            <h2>SqlDataSource</h2>
            <telerik:RadDropDownList RenderMode="Lightweight" ID="RadDropDownList2" runat="server"  Width="220px"
                DropDownHeight="200" DataSourceID="SqlDataSource1" DataTextField="ContactName" DefaultMessage="Select Customer"
                DataValueField="CustomerID">
            </telerik:RadDropDownList>
            <telerik:RadButton RenderMode="Lightweight" runat="server" Text="Select" ID="Button2"  OnClick="Button2_Click" />
            <p>
                <asp:Label runat="server" ID="Label2" />
            </p>
        </div>
        <div class="demo-container size-thin">
            <h2>XmlDataSource</h2>
            <telerik:RadDropDownList RenderMode="Lightweight" ID="RadDropDownList3" runat="server"  Width="220px"
                DataTextField="Text" DataValueField="Value" DropDownHeight="200" DefaultMessage="Select City">
            </telerik:RadDropDownList>
            <telerik:RadButton RenderMode="Lightweight" runat="server" Text="Select" ID="Button3"  OnClick="Button3_Click" />
            <p>
                <asp:Label runat="server" ID="Label3" />
            </p>
        </div>
        <div class="demo-container size-thin">
            <h2>Entity DataSouce</h2>
            <telerik:RadDropDownList RenderMode="Lightweight" ID="RadDropDownList4" runat="server"  DataSourceID="EntityDataSource1"
                 Width="220px" DataTextField="ContactName" DropDownHeight="200" DefaultMessage="Select Customer">
            </telerik:RadDropDownList>
            <telerik:RadButton RenderMode="Lightweight" runat="server" Text="Select" ID="Button4"  OnClick="Button4_Click" />
            <p>
                <asp:Label runat="server" ID="Label4" />
            </p>
        </div>

    </telerik:RadAjaxPanel>

    <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" TypeName="Telerik.Web.Examples.Movie"
        SelectMethod="GetMovieList"></asp:ObjectDataSource>
    <asp:SqlDataSource runat="server" ID="SqlDataSource1" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
        ProviderName="System.Data.SqlClient" SelectCommand="SELECT [CustomerID], [ContactName] FROM [Customers] ORDER By ContactName"></asp:SqlDataSource>
    <asp:XmlDataSource runat="server" ID="XmlDataSource1" DataFile="dropdownlist.xml"></asp:XmlDataSource>
    <asp:EntityDataSource ID="EntityDataSource1" runat="server" ConnectionString="name=NorthwindReadWriteEntities"
        DefaultContainerName="NorthwindReadWriteEntities" EntitySetName="Customers" Select="it.[ContactName], it.[City], it.[ContactTitle]"
        AutoPage="true" OrderBy="it.[ContactName]">
    </asp:EntityDataSource>

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

Support & Learning Resources

Find Assistance

Help Us Improve

Was this example helpful?