循环遍历 Vb.net 中模型类的 ArrayList [英] Looping through the ArrayList of Model Class in Vb.net

查看:57
本文介绍了循环遍历 Vb.net 中模型类的 ArrayList的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have an arraylist, that contains model class objects. Here is how I create the array list.

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 循环,但我无法访问这样的模型值.所以请告诉我,我该如何解决这个问题?

I want to use this arraylist to generate a table of records on the view page. I tried using a for loop but I cannot access the model values like that. So please tell me, how i can solve this?

我尝试做这样的事情

<% 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%>

推荐答案

你应该使用

<% 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 类型的数据.

The ViewData("rows") contains the ArrayList so we need to iterate this collection, and the ArrayList contains the data of Appointment type.

这篇关于循环遍历 Vb.net 中模型类的 ArrayList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆