我有一个填充了forename和surname的DataTable,我想在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()
这就是我现在所拥有的,但它只显示姓氏(" Nachname") 所以我的问题是如何在下拉列表中显示forename + surname作为一个项目?
答案 0 :(得分:1)
您可以在DataTable中创建一个计算列,该列是这两个字段的并集,并将其显示在DropDownList列中
dtb.Columns.Add("DataTextField", GetType(String), "forename + ' ' + surname")
ddlName.DataTextField = "DataTextField"
ddlName.DataValueField = "sozNr"