ComboBox - Programmatic Binding

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

This example demonstrates how to bind programatically RadComboBox in load on demand scenario. Also when user types it in the input field a callback is made to the server in order to request all customer names that match the typed text.

protected void RadComboBox2_ItemsRequested(object o, RadComboBoxItemsRequestedEventArgs e)
		{
            using (NorthwindReadOnlyDataContext northwindEntities = new NorthwindReadOnlyDataContext())
            {
               
                var allCustomers = northwindEntities.Customers.
                    OrderBy(i => i.ContactName);

                if (!String.IsNullOrEmpty(e.Text))
                {
                    allCustomers = northwindEntities.Customers.Where(i =>
                      i.ContactName.Contains(e.Text.Trim()))
                      .OrderBy(i => i.ContactName);
                }

				var customers = allCustomers.Skip(e.NumberOfItems).Take(10);
				RadComboBox2.DataSource = customers;
				RadComboBox2.DataBind();

				int endOffset = e.NumberOfItems + customers.Count();
				int totalCount = allCustomers.Count();

				if (endOffset == totalCount)
					e.EndOfItems = true;

				e.Message = String.Format("Items 1-{0} out of {1}",
					endOffset, totalCount);
			}
		}
  • DefaultCS.aspx
  • DefaultCS.aspx.cs
  • styles.css
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DefaultCS.aspx.cs" Inherits="ComboBox.Examples.PopulatingWithData.EntityDataSource.DefaultCS" %>

<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>

<!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-thin">
        <telerik:RadComboBox RenderMode="Lightweight" runat="server" ID="RadComboBox2" DataTextField="ContactName" 
            EnableLoadOnDemand="True" OnItemsRequested="RadComboBox2_ItemsRequested" Height="200px" Width="300"
            ShowMoreResultsBox="true">
        </telerik:RadComboBox>
    </div>

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

Find Assistance

Help Us Improve

Was this example helpful?