New to Telerik UI for ASP.NET AJAXStart a free 30-day trial

Binding to DataTable

RadDropDownList can be bound to a DataTable, DataSet, and DataView. The following example shows binding to a DataTable object.

The declaration of RadDropDownList object includes no DataSourceID property or <items> section:

ASPNET
<telerik:RadDropDownList RenderMode="Lightweight" ID="RadDropDownList1" runat="server">
</telerik:RadDropDownList>

In the Page_Load event handler, create and fill the DataTable object, then bind it to the RadDropDownList. The DataBind method must be called after setting the DataSource property.

C#
	
protected void Page_Load(object sender, EventArgs e)
{
	if (!Page.IsPostBack)
	{
		BindToDataTable(RadDropDownList1);
	}

}

private void BindToDataTable(Telerik.Web.UI.RadDropDownList dropdownlist)
{
	SqlConnection con = new SqlConnection("Data Source=LOCAL;Initial Catalog=DropDownList;Integrated Security=True");

	SqlDataAdapter adapter = new SqlDataAdapter("SELECT [Text], [Value] FROM [Links]", con);
	DataTable links = new DataTable();

	adapter.Fill(links);

	dropdownlist.DataTextField = "Text";
	dropdownlist.DataValueField = "Value";
	dropdownlist.DataSource = links;
	dropdownlist.DataBind();
}
Not finding the help you need?
Contact Support