14. July 2008 15:05
One of the cool features of ASP.NET 2.0 is the new Object Data Source, which lets you bind your business entities/objects to your ASP.NET controls. What I hate about this control is that when you open the dropdown you get a list of all the classes that are referenced in your project, which in some cases in can be a lot of them. If you check the Show only data components box then most of the time the dropdown empties out.
So how do you get your business layer classes to show as Data Components? All you have to do is add the attribute DataObject to the class. According to the MSDN documentation: "Identifies a type as an object suitable for binding to an ObjectDataSource object."
public class manager
//methods go here
Public Class Manager
'Methods go here
If your Business Layer is in a separate layer (project) from your UI then you will need to recompile. Now when you check "Show only data components" you get a smaller list with your Business Layer class.
Furthermore, you can decorate your methods with the DataObjectMethod attribute which "Identifies a data operation method exposed by a type, what type of operation the method performs, and whether the method is the default data method."
public static List<User> GetUsers()
//Implementation goes here
<DataObjectMethod(DataObjectMethodType.Select, false)> _
Public Shared Function GetUsers() as List(Of User)
'Implementation goes here
Happy Data Binding!