I am trying to do this:
protected void Page_Load(object sender, EventArgs e)
{
Group g = SecurityManager.GetGroup("Programmers");
IEnumerable<EmployeGroup> emps =
SecurityManager.GetEmployeesByGroup(g.GroupID);
ListBox1.DataSource = emps;
ListBox1.DataTextField = "Employee.EmployeName";
ListBox1.DataBind();
}
Inside an EmployeGroup there is an Employee and a Group.
I want to show the Employee’s EmployeName member.
Is there some way to do this without doing:
for each Employee. Add to listbox.
You have a few choices. You can either extend the Employee class and introduce a new property called EmployeeNameAndId
Another option is overriding the OnDataBinding event and concatenate the two properties there. I don’t recommend this; it’s lousy encapsulation among other reasons, but I wanted you to be aware of the option.
The final option is to create an intermediate data source from your query and bind to that: