Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 445
  • Last Modified:

e.Item.FindControl("ddlProduct") and SelectedItem.Text not using selected item

Hello,

I have a very unusual problem which has got me stumped.

On a page I have created there is a repeater control which has a dropdownlist that is bound with data.

The data comes from SQL via stored procs.

There are 16 different product categories each uses the same page and procs to populate the page.

On 15 of the products when selecting a item from the dropdownlist the correct item is selected and added to a shopping cart.

For 1 of the categories however no matter what selection is made it is always the first item in the list that is added.

Any ideas?

string productID = commandArgs[0];

                    string productPrice;

                    string ddlDescription;

                    DropDownList ddlPrice;

                    ddlPrice = (DropDownList)e.Item.FindControl("ddlProduct");

                    ddlDescription = ddlPrice.SelectedItem.Text;

                    productPrice = ddlPrice.SelectedValue;

Open in new window

0
Lee Redhead
Asked:
Lee Redhead
  • 4
  • 3
1 Solution
 
Kyle AbrahamsSenior .Net DeveloperCommented:
ddlPrice = (DropDownList)e.Item.FindControl("ddlProduct");


Should "ddlProduct" be "ddlPrice" ?
0
 
Lee RedheadManaging DirectorAuthor Commented:
No, ddlPrice is the control that I create in the code behind for the lookups. ddlProduct is the name of the control within the web page that is referenced. See below.

DropDownList ddlPrice;

ddlPrice = (DropDownList)e.Item.FindControl("ddlProduct");

Open in new window


The code works perfect for everything else it is just this one particular category that is causing issues. That is what I am struggling to find out why as it makes no sense.
0
 
guru_samiCommented:
Can you make sure the DropDown values are unique.
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
Lee RedheadManaging DirectorAuthor Commented:
Yes the values are unique.

One list are a set of drink options but it is always the first option that is selected.

If I use Selected.Index.ToString() in the code to set a label text value to show then it is always index 0 that is used.
0
 
guru_samiCommented:
Sorry asking the same thing again in different way...is the price for the 1st and last product the same?
0
 
Lee RedheadManaging DirectorAuthor Commented:
They are and I just looked at one of the other categories where the item description is different but the price is the same. Same thing first option selected, unless a different priced option is selected.

Please say there is an easy fix as I have overlooked something.
0
 
guru_samiCommented:
In that case you will have to make the values distinguishable.e.g. here
0
 
Lee RedheadManaging DirectorAuthor Commented:
Prefect, thank you for that. It is always something really simple.
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.

Join & Write a Comment

Featured Post

Get expert help—faster!

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

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now