New to Telerik UI for ASP.NET AJAX? Download free 30-day trial

Binding to Array or ArrayList

Both Array and ArrayList could be used as a Data Source by RadSearchBox. The following example demonstrates a valid use of both Data Sources, defining them at runtime.

Binding to Array and ArrayList at runtime

The declarations of the RadSearchBox objects does not include DataSourceID property:

<telerik:RadSearchBox RenderMode="Lightweight" runat="server" ID="RadSearchBox1" >
    <DropDownSettings Height="400" Width="300" />
</telerik:RadSearchBox>
<telerik:RadSearchBox RenderMode="Lightweight" runat="server" ID="RadSearchBox2" >
    <DropDownSettings Height="400" Width="300" />
</telerik:RadSearchBox>

One can use the Page_Load event handler to create the Array and ArrayList by setting the DataSource property of RadSearchBox accordingly.


protected void Page_Load(object sender, EventArgs e)
{
    BindToArrayList(RadSearchBox1);
    BindToArray(RadSearchBox2);
}

private void BindToArray(RadSearchBox searchBox)
{
    string[] itemsList = { "One", "Two", "Three" };
    searchBox.DataSource = itemsList;
}

private void BindToArrayList(RadSearchBox searchBox)
{
    ArrayList itemsList = new ArrayList();
    itemsList.Add("One");
    itemsList.Add("Two");
    itemsList.Add("Three");
    searchBox.DataSource = itemsList;
}


Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load

    BindToArrayList(RadSearchBox1)
    BindToArray(RadSearchBox2)
End Sub

Private Sub BindToArray(searchBox As RadSearchBox)
    Dim itemsList As String() = {"One", "Two", "Three"}
    searchBox.DataSource = itemsList
End Sub

Private Sub BindToArrayList(searchBox As RadSearchBox)
    Dim itemsList As New ArrayList()
    itemsList.Add("One")
    itemsList.Add("Two")
    itemsList.Add("Three")
    searchBox.DataSource = itemsList
End Sub

In this article