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"
dtb.Clear()
Using dad As New OleDbDataAdapter(strSql, connection)
dad.Fill(dtb)
End Using
ddlName.Items.Clear()
ddlName.DataSource = dtb.DefaultView
ddlName.DataTextField = "Nachname"
ddlName.DataValueField = "sozNr"
ddlName.DataBind()
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?
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"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.