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

Binding to Array or ArrayList

RadDropDownList can be bound either to Array or ArrayList. The following example shows how to bind RadDropDownList objects to both Array and ArrayList, at runtime.

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

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

In the Page_Load event handler, create the Array and ArrayList, and bind them to the RadDropDownList objects. The DataBind method must be called after setting the DataSource property.

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

private void BindToArrayList(Telerik.Web.UI.RadDropDownList dropDownList)
{
	ArrayList itemsList = new ArrayList();
	itemsList.Add("One");
	itemsList.Add("Two");
	itemsList.Add("Three");
	dropDownList.DataSource = itemsList;
	dropDownList.DataBind();
}

private void BindToArray(Telerik.Web.UI.RadDropDownList dropDownList)
{
	string[] itemsList = { "One", "Two", "Three" };
	dropDownList.DataSource = itemsList;
	dropDownList.DataBind();
}
Not finding the help you need?
Contact Support