通过模型类的ArrayList中的Vb.net循环 [英] Looping through the ArrayList of Model Class in Vb.net
本文介绍了通过模型类的ArrayList中的Vb.net循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个ArrayList,包含模型类的对象。下面是如何创建数组列表。
昏暗ARR作为新的ArrayList
昏暗citizenHelper作为新CitizensHelper
虽然dr.Read
昏暗任命为新的约会
appointment.AppointmentId =博士(appointment_id)
appointment.DoctorNin =博士(doctor_nin)
appointment.DoctorName = citizenHelper.getNameByNin(DR(doctor_nin))
appointment.PatientNin =博士(patient_nin)
appointment.PatientName = citizenHelper.getNameByNin(DR(patient_nin))
appointment.BookingDate =博士(booking_date)
如果博士(取消)为1,则
appointment.Cancelled = TRUE
万一
如果博士(活动)为1,则
appointment.Active = TRUE
万一
arr.Add(预约)我将添加到像这样的数组
虽然结束
ViewData的(行)= ARR
我想用这个数组列表的视图页面上生成的记录表。我试图用一个for循环,但我不能访问这样的模型值。所以,请告诉我,我怎么能解决这个问题?
我试图做这样的事情。
<%每个AP作为的ArrayList中的ViewData(行)%GT;
&所述; TR>
&所述; TD>
......<! - 现在我想说明从表中所列载的价值 - >
< / TD>
< / TR>
<%下一个AP%GT;
解决方案
您应该使用
<%每个AP作为预约的ViewData(行)作为ArrayList的%GT;
&所述; TR>
&所述; TD>
......<! - 现在我想说明从表中所列载的价值 - >
< / TD>
< / TR>
<%下一个AP%GT;
在ViewData的(行)包含ArrayList中,所以我们需要遍历此集合,并在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
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?
I tried doing something like 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%>
解决方案
You should use
<% 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%>
The ViewData("rows") contains the ArrayList so we need to iterate this collection, and the ArrayList contains the data of Appointment
type.
这篇关于通过模型类的ArrayList中的Vb.net循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文