Vikas
Vikas

Reputation: 24332

How to combine columns for DatatextFiled of DropdownList?

I have Dropdown list of Faculty Name. In my database they are stored as FirstName, LastName, MiddleName,

I want to combine it in dropdownlist

ViewData["FacultyID"] = new SelectList(faculty, "ID", "FirstName");

at place of datatextfield.

Upvotes: 1

Views: 319

Answers (2)

Alexander Taran
Alexander Taran

Reputation: 6725

ViewData["FacultyID"] = 
   new SelectList(faculty.Select(f=> new 
   {id= f.Id, Name = f.Firstname + f.LastName}), "ID", "Name");

Upvotes: 3

grega g
grega g

Reputation: 1089

You could change your sql query:

SELECT ..., COALESCE(FirstName + ' ' + MiddleName + ' ' + LastName) as FullName,...

Upvotes: 1

Related Questions