About

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

Read more ...

Blog Search


(Supports AND)

Feed

Subscribe to the RSS feed for this blog.

See this post for info on full versus truncated feeds.

Quote

I am not impressed by the Ivy League establishments. Of course they graduate the best—it's all they'll take, leaving to others the problem of educating the country. They will give you an education the way the banks will give you money—provided you can prove to their satisfaction that you don't need it.

— Peter DeVries



Navigation





<January 2025>
SMTWTFS
2930311234
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 - 9/4/2024

Totals
Posts - 2655
Comments - 2677
Hits - 2,721,318

Averages
Entries/day - 0.34
Comments/entry - 1.01
Hits/day - 346

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