$99 VS $1000+. UI Control for ASP.NET AJAX(contains chart and gridview).
DropDownList Server Side Data Binding in ASP.NET
Home > How to > DropDownList Server Data Binding to Array

KT.UI for ASP.NET DropDownList offers full support for binding to all ASP.NET 2.0 DataSource components in server side, such as SqlDataSource, EntityDataSource, and XmlDataSource. This page is arranged into two sections to set DropDownList server side data binding:
  • First part is about the basic introduction of DropDownList DataSource binding component in server side
  • Second part is ranged to display the sample ASP.NET codes for setting DropDownList DataSource binding control in server side

Brief Introduction of DropDownList Server Side Data Binding Control

To bind to a DataSource component of KT.UI for ASP.NET AJAXJ DropDownList library, users are supposed to set the DataSourceID property of PerDropDownList to the ID of the DataSource component. In addition to this, users also need to set these PerDropDownList properties: DataTextField and DataValueField to map the Text and Value properties of the items to the respective columns or fields from the data source.
By using KT.UI ASP.NET DropDownList control, users can refer to and apply the ItemDataBound event, if you need to set and map the additional columns from the data source to properties of PerDropDownList items.
The event arguments passed to the event, e.Item and e.Item.DataItem, which include the example of PerDropDownList item being bound and the DataItem to which it is bound. Users can map a property from the DataItem to the corresponding property of PerDropDownList item. Please convert the DataItem object to the proper data type at first.

Sample ASP.NET Codes for Server Side Data Binding

We have mentioned that DropDownList control for ASP.NET supports these three DataSource components in server side: SqlDataSource, EntityDataSource, and XmlDataSource. In this section, we will discuss how to set each of the three datasource component within ASP.NET Web project.

How to Set Server Side SqlDataSource

Complete ASP.NET codes below are offered to set SqlDataSource control in server side within DropDownList ASP.NET application.

<kettic:PerDropDownList ID="PerDropDownList1" runat="server" Width="200" DropDownWidth="200"
DropDownHeight="200" DataSourceID="SqlDataSource1" DataTextField="ContactName" DefaultMessage="Select..."
DataValueField="CustomerID">
</kettic:PerDropDownList>
<asp:SqlDataSource runat="server" ID="SqlDataSource1" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
ProviderName="System.Data.SqlClient" SelectCommand="SELECT [CustomerID], [ContactName] FROM [Customers] ORDER By ContactName">
</asp:SqlDataSource>

How to Set Server Side XmlDataSource

Sample ASP.NET codes below are offered to set XmlDataSource component in server side within DropDownList ASP.NET application.

<kettic:PerDropDownList ID="PerDropDownList1" runat="server" Width="200" DropDownWidth="200"
DataTextField="Text" DataValueField="Value" DropDownHeight="200" DefaultMessage="Select...">
</kettic:PerDropDownList>
<asp:XmlDataSource runat="server" ID="XmlDataSource1" DataFile="dropdownlist.xml">
</asp:XmlDataSource>

How to Set Server Side EntityDataSource

Sample ASP.NET codes below are offered to set EntityDataSource component in server side within DropDownList ASP.NET application.

<kettic:PerDropDownList ID="PerDropDownList1" runat="server" DataSourceID="EntityDataSource1" Width="200"
DropDownWidth="200" DataTextField="ContactName" DropDownHeight="200" DefaultMessage="Select...">
</kettic:PerDropDownList>
<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>
ASP.NET AJAX UI Controls