Binding Multiple Fields To Listbox In Asp.net
I'm fairly new to asp.net and especially LINQ and SQL. Say I have a table 'Employees' with fields 'Lastname', 'Firstname', and 'ID'. I want to bind this to a list box. I want the l
Solution 1:
You could try something like this:
var datasource = from employee in employees
selectnew
{
Name = employee.lastName + ", " + employee.firstName,
Id = employee.ID
};
myListBox.DataSource = datasource;
myListBox.DataTextField = "Name";
myListBox.DataValueField = "Id";
myListBox.DataBind();
This constructs a list of anonymous types from your employee table to bind your listbox to.
Post a Comment for "Binding Multiple Fields To Listbox In Asp.net"