Sorx Sorx - 1 year ago 108 Question

VB.Net Datatable into Dropdowlist using 2 rows as one Item

I got a DataTable filled with forename and surname and I want to display both as one item in a DropdownList

Dim strSql As String = "SELECT * FROM Personen"
Using dad As New OleDbDataAdapter(strSql, connection)
End Using
ddlName.DataSource = dtb.DefaultView
ddlName.DataTextField = "Nachname"
ddlName.DataValueField = "sozNr"

Thats what I have right now but it only displays the surname("Nachname")
So my question is how to display the forename + surname as one Item in the Dropdownlist?

Answer Source

You can create a calculated column in the DataTable that is the union of these two fields and display it in the DropDownList column

dtb.Columns.Add("DataTextField", GetType(String), "forename + ' ' + surname")
ddlName.DataTextField = "DataTextField"
ddlName.DataValueField = "sozNr"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download