Solved

Dropdownlist SelectedItem.Value always return default no matter selection

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

695 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