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