Binding to Arrays

Just as you can bind a server control to a DataTable, you can also bind a server control to an array. The concept is the same. The DataBind() method works for any data source. Listing 5.5 shows an ASP.NET Web Form that creates an ArrayList object and binds it to a DataGrid, a DropDownList, and a RadioButtonList.

Listing 5.5. Binding Server Controls to an ArrayList
 [VB] 01: <%@ Page Language="VB" %> 02: 03: <script runat="server"> 04: Sub Page_Load(Source As Object, E As EventArgs) 05: Dim al As New ArrayList 06: al.Add("Item 1") 07: al.Add("Item 2") 08: al.Add("Item 3") 09: al.Add("Item 4") 10: al.Add("Item 5") 11: myDataGrid.DataSource = al 12: myDropDownList.DataSource = al 13: myRadioButtonList.DataSource = al 14: Page.DataBind() ...

Get Programming Data-Driven Web Applications with ASP.NET now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.