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

If you think about it, you could actually say that software design boils down to "Where should this code go?" I think there’s a watershed moment in every developer’s career when they start to look more at their code as a structure and less as a bag of statements.

Jeremy D. Miller



Navigation





<May 2021>
SMTWTFS
2526272829301
2345678
9101112131415
16171819202122
23242526272829
303112345

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 - 4/26/2021

Totals
Posts - 2635
Comments - 2645
Hits - 2,370,455

Averages
Entries/day - 0.40
Comments/entry - 1.00
Hits/day - 363

Updated every 30 minutes. Last: 6:47 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] |