Solved

Dropdownlist SelectedItem.Value always return default no matter selection

Posted on 2003-11-14
4
843 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
  • 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

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

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…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

773 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