Tutorial :How to combine columns for DatatextFiled of DropdownList?



Question:

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.


Solution:1

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


Solution:2

You could change your sql query:

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

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »