N
nmosafi
I have a datagrid that I am binding to a custom collection, and I am
having problems with data binding in an ASP.NET datagrid (1.1
framework).
As a simple example, imagine a class called EmployeeCollection which
inherits CollectionBase, and a class called Employee which is the item
of the collection. Each employee has a manager - also an instance of
the Employee class.
The Employee class has 2 properties
public string Name { get { return this.name; } }
public Employee Manager { get { return this.manager; } }
Now I have created a datagrid with single column, "Employee Name", and
I can successfully bind my collection to it, setting the DataField to
"Name". The problem occurs when I want to add another column "Manager
Name" to the datagrid. If I set the DataField to "Manager.Name" then
it complains that the Manager.Name was not found.
The only workaround for this is to add another property ManagerName to
the Employee class and bind to that as follows:
public string ManagerName { get { return this.Manager.Name; } }
Obviously this is a simplified example - I have many datagrids,
collections, and custom classes, and have ended up adding lots of
methods to retrieve such "sub-properties". This is not ideal.
Is there any way to directly bind the datagrid to Manager's name?
Thanks
Neil
having problems with data binding in an ASP.NET datagrid (1.1
framework).
As a simple example, imagine a class called EmployeeCollection which
inherits CollectionBase, and a class called Employee which is the item
of the collection. Each employee has a manager - also an instance of
the Employee class.
The Employee class has 2 properties
public string Name { get { return this.name; } }
public Employee Manager { get { return this.manager; } }
Now I have created a datagrid with single column, "Employee Name", and
I can successfully bind my collection to it, setting the DataField to
"Name". The problem occurs when I want to add another column "Manager
Name" to the datagrid. If I set the DataField to "Manager.Name" then
it complains that the Manager.Name was not found.
The only workaround for this is to add another property ManagerName to
the Employee class and bind to that as follows:
public string ManagerName { get { return this.Manager.Name; } }
Obviously this is a simplified example - I have many datagrids,
collections, and custom classes, and have ended up adding lots of
methods to retrieve such "sub-properties". This is not ideal.
Is there any way to directly bind the datagrid to Manager's name?
Thanks
Neil