How to Bind ArrayList to DataList Control
Author: DevASP Team
Download Source Code : 707_Datalist.zip
In this article I will try to explain you how you can bind arraylist to datalist control. Here I will create application in ASP.Net 2.0 and C#
Often I have seen queries posted on different forums about binding arraylist to datalist control. So by research I reached to solution and decided to write article so that it can help beginners in solving problem. To begin with drop the datalist control, in ItemTemplate tag add the Label control and bind its text to the column table column the code of you aspx page will be look like as follows:
Now on Page load event create new ArrayList object (if ArrayList is not assessable check you have imported System.Collections namespace) add items in arraylist using arraylist add method. Now convert this arraylist to dataset by adding new table and defining new column. This chunk of code will be look like as follows:
Now in end simply bind the dataset object to datalist datasource. Your final code will be look like as follows: (Note my whole code is on page_load event)