Dynamic Drop Down List in C#

Posted on 2006-05-25
Last Modified: 2012-06-21
How do I put a link to every value in my drop down list that's being populated from database?
I have a drop down list named ddColorList and I wanted that when a color is selected it will go to a page
containing the product image on that color.

I have a class named ProductsDB that connects/calls stored procedures.
And below is the code where I populate values for ddListColors:

ClothingLine.ProductsDB products = new ClothingLine.ProductsDB();
ddListColors.DataSource = products.GetColorNames(modelNum);
ddListColors.DataTextField = "ColorName";
ddListColors.DataValueField = "ProductID";

To illustrate further what I have said above, when I select a color for example I want it to go
to the ProductsDetails page. It goes to the ProductDetails of the ProductID..

Can anyone offer some assistance, please?? I would really appreciate it. This is urgent. Thanks!
Question by:JaimeJegonia
    LVL 15

    Accepted Solution

    The question is not really making much sense to me so let me know if the answer is incorrect.

    Basically you currently have in the SelectedIndexChanged event something like

    Response.Redirect("ProductDetails.aspx?Color=" + ddListColors.SelectedValue);

    You should just change it to

    Response.Redirect("ProductDetails.aspx?Color=" + ddListColors.SelectedItem.Text);

    Author Comment

    Actually I haven't written a code in my app that puts a link to each item in the dropdown list.. YET.
    Because I don't have an idea how..

    But now you have given me an idea that I should have a function for SelectedIndexChanged event to do that.

    I'm just starting to learn C# and ASP.NET that's why I'm not very knowledgeable at this..
    LVL 15

    Expert Comment

    Oh okay that makes more sense :),

    Easiest way would be to click the events icon on the dropdownlist (lightning bolt) then in there just put the redirect like I coded above, obviously depending very much on how your target page actually works, if you haev a different page for each colour then try.

    Response.Redirect(ddListColors.SelectedItem.Text + ".aspx");

    Author Comment

    I tried this code but it doesn't work..
    Does this mean I still need to add a button?
    Can I fire the event without having to press a button??

    private void ddListColors_SelectedIndexChanged(object sender, System.EventArgs e)
        Response.Redirect("ProductDetails.aspx?PID=" + ddListColors.SelectedValue);


    Author Comment

    I figured that I needed to set AutoPostBack to true to fire the event without a button.

    LVL 15

    Expert Comment

    :), sorry I was away, does it work now?

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Training Course: Java/J2EE and SOA

    This course will cover both core and advanced Java concepts like Database connectivity, Threads, Exception Handling, Collections, JSP, Servlets, XMLHandling, and more. You'll also learn various Java frameworks like Hibernate and Spring.

    This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
    In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now