Live Chat Icon For mobile
Live Chat Icon

How to concatenate and display 2 fields in a dropdownlist

Platform: ASP.NET| Category: Dropdownlist

Method1


'Select FirstName + ’ ’ + LastName as fullname from Employees'

then use ’fullname’ as the datatextfield for the dropdownlist

Method2


Dim newColumn As New DataColumn()
With newColumn
 	.ColumnName = 'fullname'
	.DataType = System.Type.GetType('System.String')
	.Expression = 'LastName+’ ’+FirstName'
End With
ds.Tables(0).Columns.Add(newColumn)
ddlName.DataTextField = 'FullName'
ddlName.DataValueField = 'employeeid'
ddlName.DataSource = ds.Tables(0).DefaultView
ddlName.DataBind()

C#


DataColumn newColumn =new DataColumn();
newColumn.ColumnName = 'fullname';
newColumn.DataType = System.Type.GetType('System.String');
newColumn.Expression = 'LastName+’ ’+FirstName';
ds.Tables[0].Columns.Add(newColumn);
DropDownList1.DataTextField = 'FullName';
DropDownList1.DataValueField = 'employeeid';
DropDownList1.DataSource = ds.Tables[0].DefaultView;
DropDownList1.DataBind();

Share with

Share on twitter
Share on facebook
Share on linkedin

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.