Multiple class properties to display in listbox datatextfield

117 Views Asked by At

I'm currently trying to join two class properties inside an asp.net ListBox Control. I want to display the date then whether or not the appointment is AM/PM. Is this possible? Thank

Chris

Dim lstAppointments As List(Of AppointmentSlotInfo) = New List(Of     AppointmentSlotInfo)

Dim appointment1 As AppointmentSlotInfo = New AppointmentSlotInfo()
    With appointment1
        .AppointmentDate = DateTime.Now
        .AppointmentTimeSlot = "PM"
    End With

Dim appointment2 As AppointmentSlotInfo = New AppointmentSlotInfo()
    With appointment2
        .AppointmentDate = DateTime.Now.AddDays(1)
        .AppointmentTimeSlot = "AM"
    End With

lstAppointments.Add(appointment1)
lstAppointments.Add(appointment2)

lstAvailableAppointments.DataTextField = "AppointmentDate,AppointmentTimeSlot"
lstAvailableAppointments.DataSource = lstAppointments
lstAvailableAppointments.DataBind()
1

There are 1 best solutions below

0
On

Yes, go to your class and add a property with a getter. Then, in your getter body, just write

String.format("{0} {1}", First Property,  SecondProperty);

Then just reference that new property as the text field.