Wrox Programmer Forums
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old October 15th, 2004, 11:12 AM
Registered User
Join Date: Jan 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default ASP.NET C# Dropdownlist value issue

   I have been busy doing other things for a couple months so was slacking on .NET for a while. I know I solved this issue before but can't remember how.

   What I am trying to do is easy. On a ASP.net C# page, insert a dropdown list that gets populated from a MS SQL table. The user selects from the dropdown list and submit. When I try to get the value that the user selects, it is usually the value of the first record returned from the database instead of what the user selected.

   I don't have this problem when the dropdown list DON'T get the information from the database but instead put in manually. Is it because I didn't do the binding?


Old October 17th, 2004, 04:07 PM
planoie's Avatar
Friend of Wrox
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts

This sounds like you are populating the dropdown list every time the page runs. What's happening is that each time you bind the DDL to the data, you are wiping out the previous values and thus .NET can't determine that there is a "new" value selected when you post the form. You need to bind the DDL on only the first page hit:

   //call DDL binding code here
Old January 4th, 2005, 02:25 PM
Registered User
Join Date: Jan 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts

   I found that the problem is the .NET Service Pack. Best thing to do is not to install it. Hopefully they fix this issue in VS2005

Old January 4th, 2005, 08:51 PM
Friend of Wrox
Join Date: Jun 2003
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts

I think you should read Peters reply again.
The problem is not with the service pack it is with your page execution logic.
You only need to bind (or populate through any means) the DDL on the first page load.
To prevent the data binding again you need to test for a postback, Peter has provide the code for you.

This problem occurs because the page load event fires prior to the Click event of the DDL.
So when you load the drop down list, the first element is selected and it is what the Click event is using.

They say, best men are molded out of faults,
And, for the most, become much more the better
For being a little bad.

Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP.NET 1.1 dropdownlist problem jjduran ASP.NET 2.0 Basics 0 July 9th, 2006 07:04 PM
Use Dropdownlist in DetailsView using asp.net/2.0 marvz ASP.NET 2.0 Basics 1 July 1st, 2006 01:43 AM
asp.net dropdownlist cena BOOK: Beginning ASP.NET 1.0 0 March 19th, 2006 01:21 AM
DropDownList in ASP.NET shurabhavesh ASP.NET 1.0 and 1.1 Basics 3 June 1st, 2005 09:25 AM
ASP.NET Dropdownlist pvasudevan ASP.NET 1.0 and 1.1 Professional 4 August 31st, 2004 11:21 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.