473,408 Members | 2,025 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,408 software developers and data experts.

Strange problem with SelectedIndex property affecting multiple dropdownlists

RSH
Hi,

I am having this very bizarre occurance with 4 dropdown lists on my ASP .Net
page.

Each control has its own unique id. When the user selects a value from each
of the dropdownlists it is written correctly to the database.

HOWEVER...When setting the SelectedIndex property of each of the controls in
the codebehind (.net 1.1) I get an exception "A dropdownlist can not have
multiple selections." This is very odd because I am literally seeting each
control as follows:

ddlActionRequestedBy.Items(2).Selected = True

ddlActionAuthorizedBy.Items(7).Selected = True

ddlActionCompletedBy.Items(12).Selected = True

ddlActionAssignedTo.Items(80).Selected = True

So I stepped through the code to try and see what happens...and what happens
is that when I set the Selected property to true for one control all of the
controls assume the same SelectedIndex. So to verify my assumption I
commented out all but the first "ddlActionRequestedBy.Items(2).Selected =
True" so I would have expected that only that control have a value selected
on page load...BUT to my surprise each of the 4 dropdownlists had the SAME
selected value. I have triple checked all code and nowhere else on the page
am I setting selectedvalues...i dont get it.

What am I missing????

Thanks!

Ron

Feb 8 '07 #1
3 1634
First of all, I think it would help if you posted all of your code. Second,
I believe that the intended way to programmatically change the selected
index in a codebehind was to do something like the following:

ddlActionRequestedBy.SelectedIndex = 2

Using your technique works, as long as all the Items are set to
Selected=False beforehand, otherwise you will be creating a point in which
multiple Items have Selected=True, causing the exception that you mentioned.
I do not have an explanation for all the dropdownlists having the same
selected value, but it would certainly help me and anyone else reading your
posts if you posted the code. Good Luck!
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

"RSH" <wa*************@yahoo.comwrote in message
news:O0**************@TK2MSFTNGP04.phx.gbl...
Hi,

I am having this very bizarre occurance with 4 dropdown lists on my ASP
.Net page.

Each control has its own unique id. When the user selects a value from
each of the dropdownlists it is written correctly to the database.

HOWEVER...When setting the SelectedIndex property of each of the controls
in the codebehind (.net 1.1) I get an exception "A dropdownlist can not
have multiple selections." This is very odd because I am literally
seeting each control as follows:

ddlActionRequestedBy.Items(2).Selected = True

ddlActionAuthorizedBy.Items(7).Selected = True

ddlActionCompletedBy.Items(12).Selected = True

ddlActionAssignedTo.Items(80).Selected = True

So I stepped through the code to try and see what happens...and what
happens is that when I set the Selected property to true for one control
all of the controls assume the same SelectedIndex. So to verify my
assumption I commented out all but the first
"ddlActionRequestedBy.Items(2).Selected = True" so I would have expected
that only that control have a value selected on page load...BUT to my
surprise each of the 4 dropdownlists had the SAME selected value. I have
triple checked all code and nowhere else on the page am I setting
selectedvalues...i dont get it.

What am I missing????

Thanks!

Ron



Feb 8 '07 #2
"RSH" <wa*************@yahoo.comwrote in message
news:O0**************@TK2MSFTNGP04.phx.gbl...
What am I missing????
ddlActionRequestedBy.SelectedIndex = -1
ddlActionRequestedBy.Items(2).Selected = True

ddlActionAuthorizedBy.SelectedIndex = -1
ddlActionAuthorizedBy.Items(7).Selected = True
ddlActionCompletedBy.SelectedIndex = -1
ddlActionCompletedBy.Items(12).Selected = True

ddlActionAssignedTo.SelectedIndex = -1
ddlActionAssignedTo.Items(80).Selected = True
Feb 8 '07 #3
RSH
The problem was actually a little obscure and you are correct...if I had
posted the rest of the code somebody would have certainly pointed out the
problem...

I was doing this in the binding code:
While dtrReader.Read

If Not IsDBNull(dtrReader("ListDisplay")) Then

AddListitem(ddlActionRequestedBy, dtrReader("ListDisplay"),
dtrReader("FullName"))

AddListitem(ddlActionAuthorizedBy, dtrReader("ListDisplay"),
dtrReader("FullName"))

AddListitem(ddlActionAssignedTo, dtrReader("ListDisplay"),
dtrReader("FullName"))

AddListitem(ddlActionCompletedBy, dtrReader("ListDisplay"),
dtrReader("FullName"))

AddListitem(ddlCreditAuthorizedBy, dtrReader("ListDisplay"),
dtrReader("FullName"))

AddListitem(ddlCreditToBePerformedBy, dtrReader("ListDisplay"),
dtrReader("FullName"))

AddListitem(ddlCreditRequestedBy, dtrReader("ListDisplay"),
dtrReader("FullName"))

AddListitem(ddlCreditPerformedBy, dtrReader("ListDisplay"),
dtrReader("FullName"))

AddListitem(ddlResolvedBy, dtrReader("ListDisplay"), dtrReader("FullName"))

AddListitem(ddlResolutionProposedBy, dtrReader("ListDisplay"),
dtrReader("FullName"))

AddListitem(ddlResolutionAuthorizedBy, dtrReader("ListDisplay"),
dtrReader("FullName"))

AddListitem(ddlResolutionAssignedTo, dtrReader("ListDisplay"),
dtrReader("FullName"))

AddListitem(ddlResolvedApprovedBy, dtrReader("ListDisplay"),
dtrReader("FullName"))

AddListitem(ddlFollowUpAssignedTo, dtrReader("ListDisplay"),
dtrReader("FullName"))

AddListitem(ddlFollowupApprovedBy, dtrReader("ListDisplay"),
dtrReader("FullName"))

AddListitem(ddlFollowupCompletedBy, dtrReader("ListDisplay"),
dtrReader("FullName"))

AddListitem(ddlAccountantNotified, dtrReader("ListDisplay"),
dtrReader("FullName"))

End If

End While

The problem was that .Net treated those list items as references and not
values. Once I changed that then presto...everything worked fine.

Thanks!

Ron
"Nathan Sokalski" <nj********@hotmail.comwrote in message
news:uH**************@TK2MSFTNGP03.phx.gbl...
First of all, I think it would help if you posted all of your code.
Second, I believe that the intended way to programmatically change the
selected index in a codebehind was to do something like the following:

ddlActionRequestedBy.SelectedIndex = 2

Using your technique works, as long as all the Items are set to
Selected=False beforehand, otherwise you will be creating a point in which
multiple Items have Selected=True, causing the exception that you
mentioned. I do not have an explanation for all the dropdownlists having
the same selected value, but it would certainly help me and anyone else
reading your posts if you posted the code. Good Luck!
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

"RSH" <wa*************@yahoo.comwrote in message
news:O0**************@TK2MSFTNGP04.phx.gbl...
>Hi,

I am having this very bizarre occurance with 4 dropdown lists on my ASP
.Net page.

Each control has its own unique id. When the user selects a value from
each of the dropdownlists it is written correctly to the database.

HOWEVER...When setting the SelectedIndex property of each of the controls
in the codebehind (.net 1.1) I get an exception "A dropdownlist can not
have multiple selections." This is very odd because I am literally
seeting each control as follows:

ddlActionRequestedBy.Items(2).Selected = True

ddlActionAuthorizedBy.Items(7).Selected = True

ddlActionCompletedBy.Items(12).Selected = True

ddlActionAssignedTo.Items(80).Selected = True

So I stepped through the code to try and see what happens...and what
happens is that when I set the Selected property to true for one control
all of the controls assume the same SelectedIndex. So to verify my
assumption I commented out all but the first
"ddlActionRequestedBy.Items(2).Selected = True" so I would have expected
that only that control have a value selected on page load...BUT to my
surprise each of the 4 dropdownlists had the SAME selected value. I have
triple checked all code and nowhere else on the page am I setting
selectedvalues...i dont get it.

What am I missing????

Thanks!

Ron




Feb 8 '07 #4

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

Similar topics

3
by: Russell Campbell | last post by:
Posting again, since my first attempt never appeared: In the onClick method of a listbox, I am attempting to retrieve the selectedIndex property. The listbox is set up to allow multiple...
2
by: jm | last post by:
I have datagrid. On this datagrid there is a button and a dropdownlist. When I press the button, I want the selectedIndex of the dropdownlist. There is a button and a dropdownlist for each...
2
by: David Austin via .NET 247 | last post by:
Hello, I hope this is where I should post this. I have a problem with this code that I can't figure out...seems to be a bug in the dropdownlist control. I am trying to set multiple dropdownlists to...
2
by: Jim Bancroft | last post by:
Hi everyone, I have a DropDownList I populate as outlined below. This is from my code-behind file: private void Page_Load(object sender, System.EventArgs e) { BindMyData(); DataBind(); }
3
by: Jim in Arizona | last post by:
I'm going insane! I don't know if it's just that the .net 2.0 framework is buggy or if it really is my code. This is pretty hard to explain since I can't even begin to nail down why this is...
3
by: Nathan Sokalski | last post by:
I am working on a simple user control composed of 3 DropDownLists that will be used to select Dates. The purpose of the control is to all the user to choose a date using dropdown lists but not need...
1
by: Nathan Sokalski | last post by:
I have a problem that is driving me crazy. I have a User Control composed of three DropDownLists that will be used to select a date. I have everything working except for one thing. When I select a...
6
by: Nathan Sokalski | last post by:
I am writing a User Control that uses 3 DropDownLists. When I attempt to access the SelectedIndex property it incorrectly reports the value selected by the user. Why is this? Here is my code,...
0
by: ASP Developer | last post by:
I need to design a user control that will contain multiple dropdownlists. I am trying to determine the best approach to do this. I could expose every property that is necessary for all of the...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.