473,383 Members | 1,896 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Question: Dropdownlist SelectedItem always returns 1st value!

I have a dropdownlist which I populated on page_load. This works fine. I
simply do a ddlMyDdl.Items.Add(xxx)

I also have a button which references the CURRENTLY selected item in the ddl
like this:
ddlMyDdl.SelectedItem

The problem is that I am ALWAYS getting the first item back! Even when I
select the 5th item, the 10th item, etc....

Any ideas?

Thanks.
Nov 18 '05 #1
4 4663
Does each of your items have a different value? Not just text, but the value
as well?

"VB Programmer" <gr*********@go-intech.com> wrote in message
news:eT**************@TK2MSFTNGP09.phx.gbl...
I have a dropdownlist which I populated on page_load. This works fine. I
simply do a ddlMyDdl.Items.Add(xxx)

I also have a button which references the CURRENTLY selected item in the ddl like this:
ddlMyDdl.SelectedItem

The problem is that I am ALWAYS getting the first item back! Even when I
select the 5th item, the 10th item, etc....

Any ideas?

Thanks.

Nov 18 '05 #2
Do you have your .DataBind() for the ddl encapsulated in a "if
(!Page.IsPostBack)" expression? If you don't watch for postbacks, it will
re-build the items collection on the dll every time you post back and
therefore only return the currently selected item in the new collection,
namely the first item by default.

Hope this helps.
Sam

"VB Programmer" <gr*********@go-intech.com> wrote in message
news:eT**************@TK2MSFTNGP09.phx.gbl...
I have a dropdownlist which I populated on page_load. This works fine. I
simply do a ddlMyDdl.Items.Add(xxx)

I also have a button which references the CURRENTLY selected item in the ddl like this:
ddlMyDdl.SelectedItem

The problem is that I am ALWAYS getting the first item back! Even when I
select the 5th item, the 10th item, etc....

Any ideas?

Thanks.

Nov 18 '05 #3
I got it. I was clearing the ddl before I populated it in the page_load. I
had to put in a "If not page is postback" statement. Thanks.

"VB Programmer" <gr*********@go-intech.com> wrote in message
news:eT**************@TK2MSFTNGP09.phx.gbl...
I have a dropdownlist which I populated on page_load. This works fine. I
simply do a ddlMyDdl.Items.Add(xxx)

I also have a button which references the CURRENTLY selected item in the ddl like this:
ddlMyDdl.SelectedItem

The problem is that I am ALWAYS getting the first item back! Even when I
select the 5th item, the 10th item, etc....

Any ideas?

Thanks.

Nov 18 '05 #4
THANKS EVERYONE!!!!

"Sam Fields" <sf*****@state.pa.us> wrote in message
news:uF**************@TK2MSFTNGP11.phx.gbl...
Do you have your .DataBind() for the ddl encapsulated in a "if
(!Page.IsPostBack)" expression? If you don't watch for postbacks, it will
re-build the items collection on the dll every time you post back and
therefore only return the currently selected item in the new collection,
namely the first item by default.

Hope this helps.
Sam

"VB Programmer" <gr*********@go-intech.com> wrote in message
news:eT**************@TK2MSFTNGP09.phx.gbl...
I have a dropdownlist which I populated on page_load. This works fine. I simply do a ddlMyDdl.Items.Add(xxx)

I also have a button which references the CURRENTLY selected item in the

ddl
like this:
ddlMyDdl.SelectedItem

The problem is that I am ALWAYS getting the first item back! Even when I select the 5th item, the 10th item, etc....

Any ideas?

Thanks.


Nov 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Martin Schmid | last post by:
When testing for the value of my DropDownList.SelectedItem.Text - it always returns the Text of the first element of the list. It is a databound control, and I have a breakpoint in my code to test...
4
by: theo | last post by:
Program flow...load file,then extract the xml text tags from the file,then the number of Xml tags retrieved from the file determines the number of dropdownlist controls instanciated in the...
7
by: Lastie | last post by:
Hi all, I’ve got a ‘dropdownlist’ web control and I can add ‘listitem’ no problem. I can also bind data from an SQL database fine. My problem is that I want to do both at the same...
3
by: sling blade | last post by:
Hi, I have a dropdownlist in my DataList control and I am trying to set the SelectedItem property of the dropdownlist so when the datalist displays the user will see the text in the dropdownlist...
3
by: Sam C | last post by:
Hi, I have an ASP.Net page which has a DropDownList on it. The DDL is populated via a method which is called from the Page_Load if IsPostBack = False. When the form is submitted the...
2
by: HH | last post by:
Hi, I have a dropdown list that is datafilled via a SQL table. The text part is always unique. (A list of countries) Each country is assigned one of three numbers. (This being the 'value' of...
2
by: Antonio D'Ottavio | last post by:
Good morning, I've a problem with a dropdownlist located inside any row of a datalist, I fill both datalist and dropdownlist at runtime, the problem is with the dropdownlist infact using the event...
1
by: MaryamSh | last post by:
Hi, I am creating a Dynamic Search in my application. I create a user control and in Page_load event I create a dynamic dropdownlist and 2 dynamic button (Add,Remove) By pressing Add button...
0
by: MaryamSh | last post by:
Create Dynamic Dropdownlist Controls and related event -------------------------------------------------------------------------------- Hi, I am creating a Dynamic Search in my application. I...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.