About

I'm Mike Pope. I live in the Seattle area. I've been a technical writer and editor for over 30 years. I'm interested in software, language, music, movies, books, motorcycles, travel, and ... well, lots of stuff.

Read more ...

Blog Search


(Supports AND)

Google Ads

Feed

Subscribe to the RSS feed for this blog.

See this post for info on full versus truncated feeds.

Quote

Academics are always suckers for arguments that extol the virtues of superior intelligence.

Charles Morris, writing about classic liberal economics of the early 60s



Navigation





<March 2023>
SMTWTFS
2627281234
567891011
12131415161718
19202122232425
2627282930311
2345678

Categories

  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  

Contact Me

Email me

Blog Statistics

Dates
First entry - 6/27/2003
Most recent entry - 2/21/2023

Totals
Posts - 2642
Comments - 2655
Hits - 2,551,985

Averages
Entries/day - 0.37
Comments/entry - 1.00
Hits/day - 354

Updated every 30 minutes. Last: 11:45 PM Pacific


  02:56 PM

This came up at work today, so I thought I'd toss in a quick note. You can do cascading drop-down lists declaratively in ASP.NET 2.0, or at least if your scenario is straightforward. Imagine two drop-down lists on a page:



The values available in the second one depend on the selection in the first one.

Update I've also added a post about cascading drop-down list in the EditItemTemplate of a FormView control.


You can do this with two DropDownList controls, of course, and two datasource controls, each of which does a query. The first one gets all the records for the first drop-down list. The second datasource control has a parameterized query that looks like this:
SELECT Model FROM Models WHERE (Manufacturer = @Manufacturer)
(If you, like, I, are using an Access mdb file for your test, the variable is a question mark.)

The trick to this, such as it is, is in how you get the parameter value. Since the second list depends on the selection in the first list, you can create a ControlParameter to get the first list's selection. The markup for the complete second datasource control might look like this:
<asp:AccessDataSource ID="AccessDataSource2" 
runat="server"
DataFile="~/App_Data/Cars.mdb"
SelectCommand="SELECT Model, ModelID FROM Models WHERE (Manufacturer = ?) ORDER BY Model">
<SelectParameters>
<asp:ControlParameter
ControlID="DropDownList1"
Name="Manufacturer"
PropertyName="SelectedValue"
Type="String" />
</SelectParameters>
</asp:AccessDataSource>
Make sense? The query for this datasource control reads the selected value from the first drop-down list and then passes it as a parameter to the query.

This works (for me) even if the selection in the first list ends up returning no hits for the second list.

I've posted the complete page separately here.

[categories]  

[3] |