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

While it may seem counter-intuitive, teaching is an amazing way of learning—I learned more about programming by teaching it to others than I did by actually writing code. Different developers have different (sometimes way different) ideas about what is good code, and by discussing it with them, you grow (even if you were right in the first place). It also helps solidify your own arguments by forcing you to actually think them through and explain them in ways that others can understand.

Kent Sharkey



Navigation





<July 2021>
SMTWTFS
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567

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 - 6/6/2021

Totals
Posts - 2636
Comments - 2645
Hits - 2,393,419

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

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