views:

46

answers:

2
            Employee emp = new Employee();
            comHandledBySQt.DataSource = emp.GetDataFromTable("1");
            comHandledBySQt.DisplayMember = "FirstName";

The above code displays drop list of employees first names in a combo box. I want first name and last name to be displayed. How can i do it?

I tried to include two columns FirstName and LastName as below but didn't work.

comHandledBySQt.DisplayMember = "FirstName" + " " + "LastName";

Any help will be appreciated.

+1  A: 

If you need to do binding with the datasource straight away, you'll need to create a custom-view for this. Or you can iterate over rows returned from emp.GetDataFromTable() and add each row to DropDown with string.Format() or some string manipulation.

this. __curious_geek
+1  A: 

Easiest way would be to select an anonymous object with the values you wanted.

   Employee emp = new Employee();
   comHandledBySQt.DataSource = from x in emp.GetDataFromTable("1")
                    select new { x.Id, Name = x.FirstName + " " + x.LastName };
   comHandledBySQt.DisplayMember = "Name";
   comHandledBySQt.ValueMember = "Id";
schdr
I'm not very much familiar with Linq. I get this error:"Cannot convert lambda expression to type 'string' because it is not a delegate type" - keyword select become underlined with blueCan you please advice. Thanks
peace