0

我有一个数组列表,其中包含模型类对象。这是我创建数组列表的方法。

Dim arr As New ArrayList
Dim citizenHelper As New CitizensHelper
While dr.Read
    Dim appointment As New Appointment
    appointment.AppointmentId = dr("appointment_id")
    appointment.DoctorNin = dr("doctor_nin")
    appointment.DoctorName = citizenHelper.getNameByNin(dr("doctor_nin"))
    appointment.PatientNin = dr("patient_nin")
    appointment.PatientName = citizenHelper.getNameByNin(dr("patient_nin"))
    appointment.BookingDate = dr("booking_date")
    If dr("cancelled") Is "1" Then
        appointment.Cancelled = True
    End If
    If dr("active") Is "1" Then
        appointment.Active = True
    End If
    arr.Add(appointment) 'I add to the array like this
End While
ViewData("row") = arr

我想使用这个数组列表在视图页面上生成一个记录表。我尝试使用 for 循环,但我无法访问这样的模型值。所以请告诉我,我该如何解决这个问题?

我试着做这样的事情

<% For Each ap As ArrayList In ViewData("row")%>
    <tr>
        <td>
            ...... <!-- Now I want to show those value from a table here -->
        </td>
    </tr>
<% Next ap%>
4

2 回答 2

0

第一个想法:

错字?ViewData("row")ViewData("rows")

于 2012-08-26T06:06:20.320 回答
0

你应该使用

<% For Each ap As Appointment In ViewData("rows") As ArrayList %>
<tr>
    <td>
        ...... <!-- Now I want to show those value from a table here -->
    </td>
</tr>
<% Next ap%>

ViewData("rows") 包含 ArrayList,所以我们需要迭代这个集合,而 ArrayList 包含Appointment类型的数据。

于 2012-08-26T06:06:45.343 回答