I recently had to implement a pair of cascading DropDownLists for an ASP.NET Web project and found very little workable code samples on Google. Here's the code that worked for me.

The second DropDownList is enabled based on the selection made in the first and the cascade works in both directions, depending on the selection. The tricky bit was getting the index of the selection in the second drop down. I eventually found samples of the IndexOf and FindByText ListItemCollection methods on the MSDN site.

    <asp:DropDownList ID="InstrumentDDL" AutoPostBack="true"  
            Width="100" runat="server">
        <asp:ListItem Text="Select" Value="Select"></asp:ListItem>
        <asp:ListItem Text="Guitar" Value="Guitar"></asp:ListItem>
        <asp:ListItem Text="Mandolin" Value="Mandolin"></asp:ListItem>

    <asp:DropDownList ID="GuitarDDL" AutoPostBack="true"  
            Enabled="false" Width="100" runat="server">
        <asp:ListItem Text="Select" Value="Select"></asp:ListItem>
        <asp:ListItem Text="Fender" Value="Fender"></asp:ListItem>
        <asp:ListItem Text="Gibson" Value="Gibson"></asp:ListItem>
        <asp:ListItem Text="Gretsch" Value="Gretsch"></asp:ListItem>
        <asp:ListItem Text="Martin" Value="Martin"></asp:ListItem>

    protected void InstrumentDDL_SelectedIndexChanged(object sender, EventArgs e)
        // Reset GuitarDDL
        GuitarDDL.SelectedIndex = -1;

        // Dynamically enable the GuitarDDL based on InstrumentDDL selection
        if (InstrumentDDL.SelectedValue == "Guitar")
            GuitarDDL.SelectedItem.Text = "Select";
            GuitarDDL.Enabled = true;
            GuitarDDL.SelectedItem.Text = GuitarDDL.SelectedValue;
            GuitarDDL.Enabled = false;

    protected void GuitarDDL_SelectedIndexChanged(object sender, EventArgs e)
        // Every menu item refers to "Guitar" in the InstrumentDDL menu (except "Select")
        if (GuitarDDL.SelectedValue == "Select")
            // Reset InstrumentDDL menu and disable the GuitarDDL menu
                = InstrumentDDL.Items.IndexOf(InstrumentDDL.Items.FindByText("Select"));
            GuitarDDL.Enabled = false;
                 = InstrumentDDL.Items.IndexOf(InstrumentDDL.Items.FindByText("Guitar"));


New ASP.NET Goodies

by agrace 15. July 2007 17:52

Top of the list is the ASP.NET Futures release which is now available for download. The new Media Control is particularly helpful because up to now many developers had to purchase third party controls to present video in websites. The Browser History and Back Button Support is also being addressed for those of you interested in Ajax. This is an early developer preview, so you may not want to install it on your main development machine.

Speaking of Ajax, be sure to check out the new ASP.NET Ajax Control Toolkit as well as a host of new instructional videos and articles.

The new ASP.Net RSS Toolkit Version 2 has been released and enables ASP.NET applications to consume and publish RSS feeds. [More]

Some new tutorials have been added to ASP.NET Data Tutorials series.

Last but not least, get an early look at Visual Studio 2008 (aka Orcas). The official release of the 2008 line of products (Visual Studio 2008, Windows Server 2008 and SQL Server 2008) will be in Las Vegas next February.

View other SharePoint posts...

I've recently been assigned the task of setting up and documenting the SharePoint development environment. If you were dismayed by the vagaries of the installation process, you've seen nothing yet. Although SharePoint is built upon ASP.NET, this is an Office product. The Office team have always been the cash cow of Microsoft. Apparently, their priority was to make this product user friendly. And if your company is so large as to have thousands of sites, I can see no better choice than SharePoint. It really scales better than anything out there.

For smaller companies with in-house development teams, there is still a huge hole in this market and it will be filled by someone. Very few users will get to see how "friendly" it is if the IT people determine that it's too much of a pain to develop on. Not only that, but very few IT teams have the expertise required to do this properly anyway. Training in this area has been pretty non-existent up to recently. Some months back, I attended a MOSS boot camp which was one of the very first in the United States. It focused only on the installation and administration of SharePoint. If you are a developer like myself, then for the most part, you are pretty much on your own.


The Bottom Line:

  * You have to develop locally for debugging and testing
  * You need SharePoint/WSS on your local machine
  * SharePoint/WSS needs Windows Server 2003 SP1 to run
  * You need to use virtual machine(s) locally to host Windows Server 2003
  * You may need to bump up RAM (4 Gb) and possibly add a fast external drive
  * TFS support will not be available until the Orcas release


Everything You Need to Know:

  * Use Virtual PC Differencing Disks to your Advantage
  * MOSS 2007 Development - Virtual Server Set Up
  * Team-Based Development in MOSS
  * Development Tools and Techniques for Working with Code in WSS 3.0
  * How to Create a MOSS 2007 VPC Image - the Whole 9 Yards



I will be implementing the development environment myself and will report back on the outcome. I am going to set up initially with Virtual PC VHDs and difference files on a test machine and work from there. Eventually, I will deploy to a staging server which will be an exact duplicate of the live server. As for source control, I will have to wait until the Orcas release and start all over again. There is a TFS Beta 1 available for those who are interested. Note that you can still save your Web Parts in the current version of TFS. There are hacks to getting the current version of TFS to work with MOSS solutions but it's supposed to be so involved as to not warrant the time spent on it. Also, some people are saying that VMWare is faster that Virtual PC (Virtual Server if you have the license) but I am trying to get some benchmarks to support this. I can't wait to actually sit down and build something!