Dynamic Drop Down List in C#

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";
ddListColors.DataBind();

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!
JaimeJegoniaAsked:
Who is Participating?
 
GavinMannionConnect With a Mentor Commented:
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);
0
 
JaimeJegoniaAuthor Commented:
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..
0
 
GavinMannionCommented:
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");
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
JaimeJegoniaAuthor Commented:
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);
}

0
 
JaimeJegoniaAuthor Commented:
I figured that I needed to set AutoPostBack to true to fire the event without a button.

0
 
GavinMannionCommented:
:), sorry I was away, does it work now?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.