I answered a similar question yesterday
http://stackoverflow.com/questions/3199629/programmatically-add-controls-to-form/3199875#3199875
This example adds items to a List(Of T)
on button click, but you can add items to a control list however you like.
Basically you create a class with multiple object properties to be stored within it.
Then you add item's to the collection.
Imports System.Collections.Generic
Partial Class Default2
Inherits System.Web.UI.Page
''# we need to create an array of our control list class
Public Shared _empList As List(Of EmployeeList)
''# button click event
Protected Sub AddStuff
''# create a new employee
Dim emp As Employee = New Employee
With emp
.Name = "Joe"
.Company = "Acme Welding"
End With
''# add the employee to our custom array
_empList.Add(New ControlList(emp))
End Sub
''# this is our custom Employee List
''# the idea behind this is for us to store
Public Class EmployeeList
Private _employee As Employee
Public Property Employee As Employee
Get
Return _employee
End Get
Set(ByVal value As Employee)
_employee = value
End Set
End Property
Public Sub New(ByVal employee As Employee)
_employee = employee
End Sub
End Class
End Class
Note that you don't actually have to use the EmployeeList class to do this, you could simply create a list of the already existent "Employee" class that is built by L2S/EF, etc
Then you would pass _empList to the view and use a foreach loop to iterate through it.
EDIT:
Try something along these lines
public ActionResult ListEmployees()
{
List<Employee> _empList = new List<Employee>();
//'# create a new employee
Employee emp = new Employee();
{
emp.Name = "Joe";
emp.Company = "Acme Welding";
}
//'# add the employee to our custom array
_empList.Add(new emp);
return View(_empList);
}
Then in your view you do something like this
<%
foreach (var employee in Model)
{
%>
<p>Dude's Name: <%= Html.TextBoxFor(employee.Name) %></p>
<p>Dude's Company: <%= Html.TextBoxFor(employee.Company) %></p>
<%
}
%>