New to Telerik UI for ASP.NET AJAX? Start a free 30-day trial
Binding to Array or ArrayList
RadListBox can be bound to an Array or ArrayList. This example shows how to bind RadListBox objects to an Array and an ArrayList at runtime.
The declaration of the RadListBox objects includes no DataSourceID property or
ASPNET
<telerik:radlistbox id="RadListBox1" runat="server"></telerik:radlistbox>
<telerik:radlistbox id="RadListBox2" runat="server"></telerik:radlistbox>
In the Page_Load event handler, create the Array and the ArrayList, and bind them to the RadListBox objects. You must call the DataBind method after setting the DataSource property.
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindToArray(RadListBox1);
BindToArray(RadListBox2);
}
}
private void BindToArray(RadListBox listBox)
{
string[] itemsList = { "RadMenu", "RadListBox", "RadListBox" };
listBox.DataSource = itemsList;
listBox.DataBind();
}
private void BindToArrayList(RadListBox listBox)
{
ArrayList itemsList = new ArrayList();
itemsList.Add("RadMenu");
itemsList.Add("RadListBox");
itemsList.Add("RadListBox");
listBox.DataSource = itemsList;
listBox.DataBind();
}