DataBinding in ASP.NET 2.0#

ASP.NET 2.0 features a whole new DataBinding infrastructure, which allows you to define and consume data sources declaratively. Sounds fancy, and it is. If you look at last week's coding summary, you can see this in action:

<asp:ObjectDataSource ID="infoData" Runat="server" TypeName="WeFly247.UI.Proxies.PassengerWebService" SelectMethod="GetFlightData" />
<asp:GridView ID="info" Runat="Server" DataSourceID="infoData" />

As you can see, there's that new GridView control, and in stead of binding it in code (you know, set the DataSource property and don't forget to call DataBind!) you just set a DataSourceID. This is a reference to some data source object, which can now be just a control as any other (under the "more markup! less code!" motto).

Now there are a number of data source controls: SqlDataSource (accesses SQL Server), AccessDataSource (accesses Access (whew)), SiteMapDataSource (reads a sitemap file), DataSetDataSource and XmlDataSource (which speak for themselves), and last but certainly not least: the ObjectDataSource.

Now this is what I call goodness. They've finally come to their senses and realized that not everyone uses a database on the client tier. They've heard themselves say "Web Services" one time too many I guess, and this ObjectDataSource is the solution for everyone who has data living on another tier. What it does is create a new instance of the type you specify, and then call a method on it to get the data. After that, the object is disposed again but your disconnected data remains alive in the data source control.

Possibly (I'm just guessing - hoping actually - here, I haven't checked since I can't use Reflector to decompile this yet :-) ) they'll cache the object and method information (not the object itself, the documentation states clearly that it's disposed of) somehow to prevent every call from having the overhead of using reflection to find the type and the method to call. Anyway.

So in our case this little piece of markup just creates a new Web Service proxy for the passenger Web Service, calls the GetFlightData method on it (which effectively sets the whole SOAP story in action, talk about hidden complexity) and uses the returned data for data binding.

Sounds easy, and easy usually means limited. Fortunately, they've thought well about it, and provided quite a range of extra options. DataSource controls support parameters to be passed in or out, through parameter controls which can fetch their values from other controls, form fields, cookies, the new ASP.NET Profile, the query string, the session, or you can build your own. (A literal parameter value would be nice to pass in a constant though, but it doesn't seem to be there...). For example, this one fetches the user's culture from his Profile, and passes that along to the GetProducts method:

<asp:ObjectDataSource ID="advertisementData" Runat="server" TypeName="WeFly247.UI.Proxies.PassengerWebService" SelectMethod="GetProducts">
 <SelectParameters>
  <asp:ProfileParameter Name="cultureName" Type="String" PropertyName="Culture" />
 </SelectParameters>
</asp:ObjectDataSource>

And in case you were worried about two-way data, DataSource controls also support updating, deleting and inserting through other properties - again with parameters like before. For a lot more information, look at the excellent MSDN article on databinding in ASP.NET Whidbey by Early & Adopter.

So this is one of the reasons I'm pretty impressed with ASP.NET 2.0. More reasons are bound to follow - stay tuned :-)

Wednesday, April 28, 2004 9:59:20 AM (Romance Standard Time, UTC+01:00) #    Comments [1]  | 
Related posts:
Extracting OLE embedded images from emails in Outlook
Just Released: Mollom for .NET v1.0!
Updated: Setting up Source Server for TFS Builds
Mortgage Loan Excel Sheet
My "Deep Dive Into The Guidance Automation Toolkit" presentation now online!
DSL Tools session at TechDays in Belgium
Tracked by:
http://jelle.druyts.net/PermaLink.aspx?guid=5c404f1e-9abd-437c-acd8-0982c77aa33f [Pingback]
"Tactical Officer" (Tactical Officer) [Trackback]
"online casino" (online casino) [Trackback]
"hotel hot tub or jacuzzi columbia%2c sc" (hotel hot tub or jacuzzi columbia%2c ... [Trackback]
"piccanti" (piccanti) [Trackback]
"accent furniture" (accent furniture) [Trackback]
"catalogo moda" (catalogo moda) [Trackback]
"gainesville fl condos" (gainesville fl condos) [Trackback]
"projector lenses" (projector lenses) [Trackback]
"idea tesine" (idea tesine) [Trackback]
"crockpot apple butter" (crockpot apple butter) [Trackback]
"finanziamento capri" (finanziamento capri) [Trackback]
"canzone popolare" (canzone popolare) [Trackback]
"scheda lan" (scheda lan) [Trackback]
"tommaso" (tommaso) [Trackback]
"Funny Jokes" (Funny Jokes) [Trackback]
"orian rugs" (orian rugs) [Trackback]
"outcall massage boston" (outcall massage boston) [Trackback]
"cinque terre hotel" (cinque terre hotel) [Trackback]
"miami beach real estate listings" (miami beach real estate listings) [Trackback]
"posing in the nude" (posing in the nude) [Trackback]
"ugly teen nude" (ugly teen nude) [Trackback]
"doxycycline ingredients" (doxycycline ingredients) [Trackback]
"esercizio" (esercizio) [Trackback]
"concord realty group" (concord realty group) [Trackback]
"mondadori informatica" (mondadori informatica) [Trackback]
"whistler bc accommodation" (whistler bc accommodation) [Trackback]
"Nice look" (Nice) [Trackback]

 

Wednesday, March 22, 2006 3:54:52 AM (Romance Standard Time, UTC+01:00)
Thanks for the post. Your explination is much better than what I have been trying to tell my team. I feel there are a few things in .NET 2.0,which were done to benefit the newie developer, this begin one of them. i seem to remeber some msdn article a whi;e back that used reflection to do two-way binding, and it cached this info.

Keep up the good posts!

Cheers,
Jonathan
Comments are closed.
All content © 2008, Jelle Druyts
On this page

Recent Photos
www.flickr.com
This is a Flickr badge showing public photos from Jelle Druyts. Make your own badge here.
Advertising
Top Picks
Statistics
Total Posts: 344
This Year: 7
This Month: 0
This Week: 0
Comments: 522
Archives
Sitemap
Disclaimer
This is my personal website, not my boss', not my mother's, and certainly not the pope's. My personal opinions may be irrelevant, inaccurate, boring or even plain wrong, I'm sorry if that makes you feel uncomfortable. But then again, you don't have to read them, I just hope you'll find something interesting here now and then. I'll certainly do my best. But if you don't like it, go read the pope's blog. I'm sure it's fascinating.

Powered by:
newtelligence dasBlog 2.0.7226.0

Sign In