The Design-Time Developer

Playing with ObjectDataSource

After my Green Bay MSDN Event today, some audience members stuck around and we explored some additional features of ASP.NET 2.0.  One control of particular interest was the ObjectDataSource.  In today's session, I had demonstrated tying the ObjectDataSource control to a business object contained within the existing project.  Not having played around with the control too much yet, we took a look at how far the scope reached.

Since most business logic layers in n-tier application design implement the business objects in a separate project or library from the presentation layer, we simulated this.  I took the code from the day's event and adapted it into a separate class with a method that returned a DataSet.  By simply adding a reference to the new DLL that I generated, the ObjectDataSource control automatically detected the new class within the Configure Data Source Wizard!

I tip my hats to the members of the ASP.NET team, who apparently think of everything.

Published Wednesday, September 01, 2004 1:15 AM by jacobcy
Filed under:

Comments

 

Mark Heimonen said:

Hmmn...I've been playing around with the objectDataSource as well (see my blog entry on <a href="http://codebehind.blogspot.com/2004/09/aspnet-20-exploring-objectdatasource.html">codeBehind.blogspot.com</a> . I tried using the objectDataSource with my existing business object library written in c# v1.1. The "Configure Data Source" wizard was empty, but that may be because none of my classes return DataSets (My classes return collections of strongly typed objects) I was able to manually bind my objects to the GridView with very little effort, which was cool.

In a recent MSDN Event I attended, I was shown how the GridView and DetailView controls can automatically write back the database using the dataSource controls, so I was hoping the same would be true for the objectDataSource. To an extent this is true, but they expect your objects to accept a single insert or update statement with all of the arguements passed in as parameters. Since writing my blog, I've discovered a few MSDN articles on the subject:

<a href="http://lab.msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_aspnetcon/html/45fb67ee-9be7-49b7-9421-e242203dafa4.asp">Using Parameters with the objectDataSource Control</a>

and

<a href="http://lab.msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/T_System_Web_UI_WebControls_ObjectDataSourceMethodEventArgs.asp">object DataSourceMethodEventsArgs</a>

These two articles provide a couple alternative routes. In the first, they claim that you can use a method that takes in an object as a single parameter, using a Model-View-Controller paradigm. This would be a useful feature.

The second article discusses capturing the parameter insert event, and manually mapping the parameters back to the object. Since the main reason I would use the gridView + objectDataSource controls would be to save time, I assumed this type of mapping should take place automatically. I wouldn't want to embed this type of logic in my web pages. Basically, I just want the objectDataSource to be able to automatically use the publically exposed properties to perform the update.

I may look into creating a wrapper class containing the objectDataSource and gridView controls to see if I can create an object that automatically performs the mappings when capturing the parameter insert event.
September 7, 2004 12:37 PM
 

The Design Time Developer Playing with ObjectDataSource | Hair Growth Products said:

June 9, 2009 4:32 AM
New Comments to this post are disabled

This Blog

Syndication

News

This is the blog of Jacob Cynamon, Microsoft developer community champion (DCC) for Illinois, Indiana, and Wisconsin.


All postings on this blog are provided "AS IS" with no warranties, and confer no rights. All entries in this blog are my opinion and don't necessarily reflect the opinion of my employer.

Developer Events

Other Microsoft Events TechNet Briefings
[IT Pros]


Connections
[Small/Mid-Sized Business Owners]


TS2 Seminars
[MS Partners]


MBS
[Business Professionals]


Stay up-to-date on developer happenings
Localized MSDN Flash Newsletter

© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Microsoft
Page view tracker