Dynamic Drop Down List in C#

Posted on 2006-05-25
Medium Priority
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
  • 3
  • 3
LVL 15

Accepted Solution

GavinMannion earned 750 total points
ID: 16758970
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

ID: 16759044
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

ID: 16759086
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");
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 16759096
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

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

LVL 15

Expert Comment

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

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses
Course of the Month13 days, 13 hours left to enroll

757 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