Welcome to MSDN Blogs Sign in | Join | Help

Visual Web Developer Team Blog

Your official information source from the Visual Web Developer team.

News

  • These postings are provided "AS IS" with no warranties, and confer no rights. Use of included code samples are subject to the terms specified Terms of Use
Dynamic Data Website: Setting selection in a list from the URL

Bradley’s earlier post, ASP.NET Dynamic Data Preview Released on MSDN Code Gallery, outlined the functionality the ASP.NET Dynamic Data is offering and the walkthrough steps of how to create a Dynamic Data website using the wizard. In this post, I just want to explain a little bit how the selection between modules can “magically” work.

Let’s create a website having the following structure:

Categories/List.aspx
         CategoryList
         ProductList
Categories/Details.aspx
        CategoryDetails

To construct this web site, we would need to:

  1. Through the Dynamic Data Website Wizard, add Categories and Products tables to the model
  2. Add the Category List module.
  3. Add the Product List module to the same page as Category List. This can be done by selecting the List.aspx page on the right column, selecting the List module under the Product, then clicking on the right arrow button

    Image1
  4. Add the Category Details to another page by selecting the Website node on the right panel first, then double-clicking on the Category Details module on the left column.

    Image2

When you run the website (Ctrl-F5 from the Default.aspx file), you would see the following page:

Image3

Click on the Categories link to navigate to the Categories/List.aspx page. You would see the page as shown below.

Image4

Notice that the Product List is filtered by the selection in the Category List.

If you select the 4th row in the Category List (the selected row is highlighted), only the products under the “Dairy Products” Category will be shown in the Product List.

Image5

This works through setting the DynamicControlParameter in the LinqDataSource control for the Products.List module, so that when you click ‘Select’ on a row in the Category List, the Product List table is updated to show only products under that category. If you look at the source view of the Category/List.aspx file, you would find the following markup:

          Code

Now let’s look at the relationship between the Category.Details and Product.List. If you click on the Details link of the second row in the Category.List for the Condiments category, it will navigate to the Categories/Details.aspx as follows:

Image6

If you click on the “View Products” link, it will take you back to the Categories/List.aspx page. This time, the “Condiments” row in the Categories.List is selected, and the Products.List shows only products under the “Condiments” category as seen in the screen shot below.

Image7

How does the Categories.List know to set the corresponding selection from the URL string? This is because in the CustomPages\Categories\List.aspx.cs file, we register the ListView control of the Categories.List module with the DynamicDataManager through the call DynamicDataManager1.RegisterControl, with the setSelectionFromUrl parameter set to True. When the query string contains the primary key of the registered control, the control will set the selection on the row that matches the value of the primary key. If the registered control’s primary key is not found in the query string, then nothing will be selected. This is different from having the Categories.List to have the DynamicQueryStringParameter since it would cause a filtering, not a selection, on the Category.List (that means the Category.List would only show the rows for the requested category, instead of showing all the rows and having the row that matches the requested category selected).

Anh Phan | SDET / Visual Studio Web Developer

Posted: Tuesday, May 13, 2008 11:13 PM by WebDevTools

Comments

yousaid said:

This tool is great ! Saves a developer from writing lots of repetative codes for simple projects.

Can you point me to a tutorial on how to customize the template, I mean for example, say I already have my own MasterPage that I want to use and the basic one tht'a included?

cheers,

yousaid

# May 14, 2008 9:41 AM

Mr. Sustainable said:

In my experience, many very good web designers struggle with interacting with data sources. It was the same way for me at first. Not only will this second iteration of data scaffolding save time but it will enable those web designers to move into data integration smoothly and comfortably.

# May 15, 2008 8:44 AM

rogerj said:

Does the Dynamic Data Wizard require an upgrade for use with ASP.NET 3.5 SP1?

If so, when do you expect it to be available?

--rj

# May 15, 2008 12:51 PM

WebDevTools said:

There is a presentation at Mix 2008, http://www.asp.net/learn/mix-2008-presentations/video-307.aspx, that gives you an overview of how to customize the generated templates. However, it doesn't specifically mention about the MasterPage though. We might have a more complete tutorial series later.

# May 15, 2008 2:48 PM

WebDevTools said:

The Dynamic data Wizard requires that you first upgrade to Visual Studio 2008 SP1 Beta or .NET Framework 3.5 SP1 Beta. More info about where to install those can be found at http://code.msdn.microsoft.com/dynamicdata.

# May 15, 2008 2:55 PM

ctl00$_$ctl00$_$ctl02$_$form$_$tbname said:

gaelic World <a href= http://world.barerube.cn >search World</a> [url=http://world.barerube.cn]search World[/url]

# May 18, 2008 6:06 PM

ctl00$_$ctl00$_$ctl02$_$form$_$tbname said:

dust land wear printable from history promised in shanghai war bialystok study oral oral history palgrave <a href= http://bedebuco.cn/bialystok-dust-from-history-history-in-land-oral-oral-palgrave-promised-shanghai-study-war-wear.html >dust oral study palgrave land history oral wear shanghai war promised history god from bialystok in</a> [url=http://bedebuco.cn/bialystok-dust-from-history-history-in-land-oral-oral-palgrave-promised-shanghai-study-war-wear.html]dust oral study palgrave land history oral wear shanghai war promised history god from bialystok in[/url]

# June 8, 2008 2:19 PM
New Comments to this post are disabled
Page view tracker