Introduction
As we edge closer to the release of .NET 3.5, we get ever closer to a technology wave that has caused a major viral
campaign throughout the internet. This is especially true for LINQ and Silverlight 1.0 (not in the Orcas timeframe, but even
before!).
Both LINQ and Silverlight address complex problems. On one side we have a set of new language constructs and API that blur
the lines between data and objects. On the other hand we have a technology which breaks the boundaries of the presentation
layer used for internet applications.
Some of the features that I cover in this article are part of the ASP.NET Futures July CTP.
Note: I will be covering LINQ in this article in a context which the reader is inclined to know a little about
the technology - if your don't, why not read the Introducing LINQ series I did a while back here on DotNetSlackers?
Data != Objects
I start under the heading that Anders Hejlsberg has used as his starting slide for years when talking about the LINQ
project. Previously in ASP.NET 2.0 there was a control called ObjectDataSource which blew the doors open with
regards to plugging into a data access layer, whether we were dealing with a typed DataSet or some custom O/R mapping.
In part 4 of my "Introducing LINQ" series I used the ObjectDataSource to plug into a LINQ to SQL data access
layer (DAL). This worked fine but in order to support, for example, sorting; it required some boilerplate code. The
LinqDataSource control promises to eliminate such code.
It is my estimation that web developers will consume LINQ quickly. It offers the developer an easy, quick and powerful way
to interact with several data stores, providing rapid application development in a space that is typically associated with
repetitive, non-flexible O/R mapping boilerplate code that is a mere formality of an application that consumes some data from
an external source.
LinqDataSource
The LinqDataSource has stalked the web for months and months but the public haven't been able to use it until
the release of .NET 3.5 Beta 2 - well now it's here! Coupled with the go live license with .NET 3.5 Beta 2 this could be a
great time for early adoption.
First steps
The first step towards using a LinqDataSource control is to go ahead and create a view of your database. You
can do this in a few different ways. The first is by using the LINQ to SQL designer; the second is by using the
SqlMetal command line tool (I believe that this is now used by the LINQ to SQL designer under the covers as of
Beta 2). Finally, you can go ahead and manually create a class that derives from the
System.Data.Linq.DataContext class; and implement your database view from there.
In this article, I'm going to use the LINQ to SQL class designer to create an application view of my database.
Figure 1: LINQ to SQL Classes designer

Hooking the LinqDataSource up with our DataContext
This is great for me to see! After 14 months of playing with LINQ, the code that I am about to show you really
encompasses what LINQ is all about - accessing data quickly, simply and flexibly.
Listing 1: Using the LinqDataSource with a GridView
In the previous listing, we select all the customers from our NorthwindDataContext class (I'm
using this all within a file based web site. If you're dealing with a web application project remember to prefix the name of
the DataContext class with the projects namespace).
Figure 2: The result

Being more specific
At the moment, we are dragging everything back. This time I want to only display the ContactName,
CompanyName and City of each customer.
Listing 2: Defining the data we want
I'm going to be a little pickier now and select only those contacts that are from London.
Listing 3: Only those from London please
Figure 3: London is my favourite city

I'm not
too happy about the ordering of the names and titles of the columns of the GridView control, so I'm going to change them now.
Listing 4: A little tweaking
Note: I've not touched the GridView since Listing 1. All changes reside within the LinqDataSource control.
The LinqDataSource control is simply awesome. I invite you to play with it yourself and harness the
great functionality that you can leverage by combining LINQ to SQL with the LinqDataSource control.
Media control
This control is contained in the ASP.NET Futures CTP. Thus, you will have to register the Microsof.Web.Preview assembly
either with a Register directive or in the web.config file.
Listing 5: Registering Microsoft.Web.Preview
In the upcoming section I will use the designer, since the designer integration here is really nice.
Setting up
After you have registered the control, you simply use the asp:Media control.
Figure 4: The media control

Looks pretty nice,
doesn't it? With regards to the skin of the player, there are quite a few you can choose from. I'll let you look at those in
your own time.
The significant thing about the media control is not the way it looks, but the ability to do great stuff pragmatically
using your favored language and a nice API. This control makes it very easy for us to go ahead and embed video into a web
form using Silverlight 1.0 as the presentation platform.
In the above example I pointed the Media control at a video hosted on Channel9.
Figure 5: Media

The simplicity of the
Media control is probably its greatest asset. The above example only took a few lines of ASP.NET markup and I
got a great looking UI which encapsulated streaming logic and visuals to boot. I see this control being very popular.
ListView control
The ListView control allows you to define a standard template that all your data will use when rendered.
Listing 7: The ListView
In the previous listing we have a ListView that is bound to the data coming from the
LinqDataSource. The ListView defines a LayoutTemplate that can be thought of as a
parent to the actual containing element, which in this case is a div (asp:Panel) with the special
ID of itemContainer. The control that holds your item template must be given the ID
of itemContainer. The ItemContainer simply defines the visuals of each item that our
ListView will show.
Figure 6: The ListView

You will notice that in
Figure 6 I have used some CSS to make each contact look like a contact card (well, a very primitive one!).
The ListView provides a great way to generate well defined HTML when working with data. It's a control that
encourages the embracing of CSS to make it easier for the developer to quickly create great looking data-oriented
applications.
The DataPager control
We have already seen the DataPager control in the previous ListView section. It allows us to
provide custom paging to the ListView control. It's more than a "next and back" control; it allows for a very
fine level of customization-just like the ListView does-so you can be as expressive as you want with your
ListView and then mould a DataPager that has a similar look and feel as well as textual labels.
Listing 8: A modified ListView and DataPager using the UpdatePanel
In the previous listing we have created a really smooth way to view the contacts from our database. If you
download the sample code and give the demo a go, you will see that the ListView and DataPager are
really made for each other. When you take that visual refresh away you can create a pretty compelling UX.
Summary
I think I've touched on some of the big new controls coming our way in the future, both in the Orcas timeframe and with
ASP.NET Futures. There is stuff that I have missed; maybe in the coming weeks I will do one big article about the ASP.NET
Futures.
In the ASP.NET Futures there are many new controls, like the SearchDataSource (that allows you to plug into
Live search really easily), as well as support for dynamic languages including new dynamic controls.
In the Orcas release, ASP.NET AJAX will support WCF services. Actually, it does now in .NET 3.5 Beta 2! This is a great
new addition to ASP.NET AJAX.
As always, I encourage you to download the .NET 3.5 and ASP.NET Futures July CTP bits and take the new controls and
functionality for a test spin!
About Granville Barnett
 |
Sorry, no bio is available
This author has published 32 articles on DotNetSlackers. View other articles or the complete profile here.
|
You might also be interested in the following related blog posts
TreeView in ComboBox, take 3 (Silverlight 3, WPF and RadControls)
read more
Simple Silverlight 2 Progress Bar for Web Services
read more
Horizontal Table for your reports
read more
Silverlight Slider and Absolute values
read more
Fill My Prism Region, Please
read more
Consolas Font in Vista
read more
The Wrap Panel
read more
RADactive I-Load 2008.R1 released - Wysiwyg image upload-resize-crop tool
read more
Silverlight Slider and Absolute values
read more
Silverlight Presentations On the Horizon
read more
|
|
Please login to rate or to leave a comment.