Solved

Dropdownlist SelectedItem.Value always return default no matter selection

Posted on 2003-11-14
4
850 Views
Last Modified: 2008-02-01
Hi, need some help troubleshooting this one.  I'm coding asp.net and c# and using a dropdownlist (ddl) control on a webform.  I bound the items in the Page_Load() from a ms access database.  The ddl lists the correct items in the browser but it doesn't matter what I select in the ddl, the SelectedItem.Value or Text will always return the default value (1st entry in list).  The strange thing is when I add to the list using the Items in the properties, then it works.  Appreciate any help you can provide.
0
Comment
Question by:yuen_wc
[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
  • 2
4 Comments
 
LVL 9

Accepted Solution

by:
Joeisanerd earned 50 total points
ID: 9753245
First thing you need to do is check to see if the list is empty, if not read the selecteditem.  It sounds like you are overwriting the list by bounding it each time.

Try this
if( !IsPostBack)
{
    .....
   ddl.DataBind();
}

Check to see if it is not a post back insures that it only binds it once. Remeber that the page_load event happens before the other events, like SelectedItemChange.
0
 
LVL 10

Expert Comment

by:ptmcomp
ID: 9754450
Yes, when the site is posted back then the object is created again on the server. When you recreate the items you loose the information.
0
 

Author Comment

by:yuen_wc
ID: 9757303
IsPostBack did the trick.  Thank you for the help.  Off topic, if you have the same item appear multiple times in a database column and only want to bind it once, how would you do that?
0
 
LVL 9

Expert Comment

by:Joeisanerd
ID: 9757440
The database has it multiple times? Then fix your query to only show the UNIQUE or DISTINCT rows for that column. If it is an issue of doubling the list, then you need to erase the dropdownlist before binding it. ddl.Items.Clear, then ddl.DataBind();
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
Input parameteres to DragOver 2 58
Code works but breaks when I add one section 4 35
Pdf not loading 2 39
How does this modal gets closed? 6 41
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.
Suggested Courses

737 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