Reputation: 123
Here is my class
Public Class TitleV_List
Public Full_Name As String
Public ID As Integer
Sub New(ByVal Full_Name As String, ByVal ID As Integer)
Me.Full_Name = Full_Name
Me.ID = ID
End Sub
End Class
Here is my code:
Dim TitleVList As New List(Of TitleV_List)
con = New SqlConnection(connectionString)
sql = "Select ID, Full_Name FROM cts_TitleV_Leads WHERE IsActive = 1"
If con.State = ConnectionState.Closed Then
con.Open()
End If
cmd.CommandType = CommandType.Text
cmd.Connection = con
cmd.CommandText = sql
dr = cmd.ExecuteReader
If dr.HasRows = True Then
While dr.Read
TitleVList.Add(New TitleV_List(dr("Full_Name"), dr("ID")))
End While
End If
If con.State = ConnectionState.Open Then
con.Close()
dr.Close()
End If
ddlpropTitleVlist.DataSource = TitleVList
I check the code and the correct values are going into the dropdownlist but on the screen when I click on the dropdown Arrow all the values are: 'CTSnet.TitleV_List'
The project name is CTSnet. What am I doing wrong????
Upvotes: 0
Views: 166
Reputation: 875
You need to do two things to make this work. First, set DisplayMember and ValueMember for ddlpropTitleVlist. Something like the following right after you set the DataSource:
ddlpropTitleVlist.DisplayMember = "Full_Name"
ddlpropTitleVlist.ValueMember = "ID"
And further, you need to be pointing those members at properties of your TitleV_List class:
Public Property Full_Name As String
Public Property ID As Integer
(While we're talking about stuff, I think you should remove "_List" from that class name because it's not a list of any sort. Maybe call it TitleV_Item and then your TitleVList will suggest a list of items rather than incorrectly suggesting a list of lists.)
Upvotes: 2