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
<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.
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();
}
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
If Not IsPostBack Then
BindToArray(RadListBox1)
BindToArray(RadListBox2)
End If
End Sub
Private Sub BindToArray(ByVal listBox As RadListBox)
Dim itemsList As String() = {"RadMenu", "RadListBox", "RadListBox"}
listBox.DataSource = itemsList
listBox.DataBind()
End Sub
Private Sub BindToArrayList(ByVal listBox As RadListBox)
Dim itemsList As New ArrayList()
itemsList.Add("RadMenu")
itemsList.Add("RadListBox")
itemsList.Add("RadListBox")
listBox.DataSource = itemsList
listBox.DataBind()
End Sub