RadListBox for ASP.NET AJAX

RadControls for ASP.NET AJAX

RadListBox supports binding to all ASP.NET 2.0/3.5 DataSource components, including

  • AccessDataSource

  • SqlDataSource

  • XmlDataSource

  • ObjectDataSource

  • LinqDataSource

  • EntityDataSource

  • OpenAccessDataSource

To bind to a DataSource component, all you need to do is set the DataSourceID property of the ListBox to the ID of the DataSource component. You should also set the DataTextField and DataValueField properties of the ListBox to map the Text and Value properties of the items to the respective columns/fields from the data source.

If you need to map additional columns from the data source to properties of the ListBox items, you can use the ItemDataBound event. The event arguments passed to the event, e.Item and e.Item.DataItem, hold the instance of the ListBox item being bound and the DataItem to which it is bound. You can map a property from the DataItem to the corresponding property of the ListBox item. Be sure to cast the DataItem object to the proper data type first.

AccessDataSource

CopyASPX
<telerik:RadListBox ID="RadListBox1"
       runat="server"
       DataTextField="Name"
       DataValueField="ID"
       DataSourceID="AccessDataSource1">    
</telerik:RadListBox>
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
   DataFile="~/App_Data/Countries.mdb"
   SelectCommand="SELECT [ID], [Name] FROM [Countries]">
</asp:AccessDataSource>

SqlDataSource

CopyASPX
<telerik:RadListBox ID="RadListBox1"
   runat="server"
   DataTextField="ProductName"
   DataValueField="ProductID"
   DataSourceID="SqlDataSource1">    
</telerik:RadListBox>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
   ConnectionString="<$ ConnectionStrings>"
   SelectCommand="SELECT [ProductID], [ProductName] FROM [Products]">
</asp:SqlDataSource>

XmlDataSource

CopyASPX
<telerik:RadListBox ID="RadListBox1"
       runat="server"
       DataTextField="Text"
       DataValueField="Value"
       DataSourceID="XmlDataSource1">        
</telerik:RadListBox>
<asp:XmlDataSource ID="XmlDataSource1"
       runat="server"
       DataFile="~/ListBox.xml">
</asp:XmlDataSource>

When using an XmlDataSource, the XML file should have the format shown below:

CopyXML
<Items>
      <Item Text="New York" Value="1" />
      <Item Text="Paris" Value="2" />
      <Item Text="London" Value="3" />
 </Items>

ObjectDataSource

CopyASPX
<telerik:RadListBox ID="RadListBox1"
       runat="server"
       DataTextField="Text"
       DataValueField="ID"
       DataSourceID="ObjectDataSource1">        
</telerik:RadListBox>
<asp:ObjectDataSource ID="ObjectDataSource1"
      TypeName="ListObjectData"
      SelectMethod="GetItems"
      runat="server">
</asp:ObjectDataSource>

LinqDataSource

CopyASPX
<telerik:RadListBox ID="RadListBox1"
   runat="server"
   DataTextField="ProductName"
   DataValueField="ProductID"
   DataSourceID="LinqDataSource1">
</telerik:RadListBox>
<asp:LinqDataSource ID="LinqDataSource1" runat="server"
       ContextTypeName="NorthwindDataContext"
       Select="new (ProductID, ProductName)"
       TableName="Products">
</asp:LinqDataSource>

EntityDataSource

CopyASPX
<telerik:RadListBox runat="server" ID="RadListBox1" Height="200px" Width="200px"
    DataSourceID="EntityDataSource1" DataTextField="ContactName">
</telerik:RadListBox>
<asp:EntityDataSource ID="EntityDataSource1" runat="server"
    ConnectionString="name=NorthwindEntities"
    DefaultContainerName="NorthwindEntities"
    EntitySetName="Customers"
    Select="it.[ContactName], it.[City], it.[ContactTitle]"
    AutoPage="true" OrderBy="it.[ContactName]">
</asp:EntityDataSource>

See Also