Solved

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

Posted on 2013-01-17
8
439 Views
Last Modified: 2013-01-17
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
Comment
Question by:Lee Redhead
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 38788240
ddlPrice = (DropDownList)e.Item.FindControl("ddlProduct");


Should "ddlProduct" be "ddlPrice" ?
0
 

Author Comment

by:Lee Redhead
ID: 38788256
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
 
LVL 41

Expert Comment

by:guru_sami
ID: 38788424
Can you make sure the DropDown values are unique.
0
Independent Software Vendors: 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

by:Lee Redhead
ID: 38788540
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
 
LVL 41

Expert Comment

by:guru_sami
ID: 38788601
Sorry asking the same thing again in different way...is the price for the 1st and last product the same?
0
 

Author Comment

by:Lee Redhead
ID: 38788682
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
 
LVL 41

Accepted Solution

by:
guru_sami earned 500 total points
ID: 38788708
In that case you will have to make the values distinguishable.e.g. here
0
 

Author Closing Comment

by:Lee Redhead
ID: 38788911
Prefect, thank you for that. It is always something really simple.
0

Featured Post

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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Convert Silverlight ERP To Angularjs,HTML5 3 58
need to convert function to c# 5 43
C# Service FileSystemwatcher isse 9 46
Validating textboxes in red square borders. 2 33
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

749 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