By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,573 Members | 1,208 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,573 IT Pros & Developers. It's quick & easy.

When I set the DropDownList.SelectedIndex of ONE DropDownList they ALL change!

P: n/a
S_K
Hi,

I have a list of 6 DropDownList boxes, from DropDownList1 to
DropDownList6, and I'm changing the SelectedIndex of each using a
foreach loop as follows:

foreach(PaymentReqDisplay thispayment in listPaymentReqDisplay)
{
if ((string)thispayment.TaxType == "FIT")
this.DropDownList1.SelectedIndex =
(int)thispayment.PaymentRequirementID - 1;
if ((string)thispayment.TaxType == "FUI")
this.DropDownList2.SelectedIndex =
(int)thispayment.PaymentRequirementID - 1;
if ((string)thispayment.TaxType == "SIT")
this.DropDownList3.SelectedIndex =
(int)thispayment.PaymentRequirementID - 1;
if ((string)thispayment.TaxType == "SUI")
this.DropDownList4.SelectedIndex =
(int)thispayment.PaymentRequirementID - 1;
if ((string)thispayment.TaxType == "ETF")
this.DropDownList5.SelectedIndex =
(int)thispayment.PaymentRequirementID - 1;
if ((string)thispayment.TaxType == "SDI")
this.DropDownList6.SelectedIndex =
(int)thispayment.PaymentRequirementID - 1;
}

The problem is that when I change, say, DropDownList4.SelectedIndex =
3; every other DropDownList's SelectedIndex changes as well!?

What am I doing wrong?

Thanks much for your help.
Steve

Nov 13 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Do all ddls share the same items?

When you set the SelectedIndex property, it actually sets the Selected
property of the item you select. Thus the same item becomes selected in all
ddls it is participating.

The solution is to replicate the item collection for every single ddl.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"S_K" <st***********@yahoo.comwrote in message
news:11**********************@22g2000hsm.googlegro ups.com...
Hi,

I have a list of 6 DropDownList boxes, from DropDownList1 to
DropDownList6, and I'm changing the SelectedIndex of each using a
foreach loop as follows:

foreach(PaymentReqDisplay thispayment in listPaymentReqDisplay)
{
if ((string)thispayment.TaxType == "FIT")
this.DropDownList1.SelectedIndex =
(int)thispayment.PaymentRequirementID - 1;
if ((string)thispayment.TaxType == "FUI")
this.DropDownList2.SelectedIndex =
(int)thispayment.PaymentRequirementID - 1;
if ((string)thispayment.TaxType == "SIT")
this.DropDownList3.SelectedIndex =
(int)thispayment.PaymentRequirementID - 1;
if ((string)thispayment.TaxType == "SUI")
this.DropDownList4.SelectedIndex =
(int)thispayment.PaymentRequirementID - 1;
if ((string)thispayment.TaxType == "ETF")
this.DropDownList5.SelectedIndex =
(int)thispayment.PaymentRequirementID - 1;
if ((string)thispayment.TaxType == "SDI")
this.DropDownList6.SelectedIndex =
(int)thispayment.PaymentRequirementID - 1;
}

The problem is that when I change, say, DropDownList4.SelectedIndex =
3; every other DropDownList's SelectedIndex changes as well!?

What am I doing wrong?

Thanks much for your help.
Steve

Nov 14 '07 #2

P: n/a
S_K
On Nov 14, 2:52 am, "Eliyahu Goldin"
<REMOVEALLCAPITALSeEgGoldD...@mMvVpPsS.orgwrote:
Do all ddls share the same items?

When you set the SelectedIndex property, it actually sets the Selected
property of the item you select. Thus the same item becomes selected in all
ddls it is participating.

The solution is to replicate the item collection for every single ddl.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net

"S_K" <steve_kers...@yahoo.comwrote in message

news:11**********************@22g2000hsm.googlegro ups.com...
Hi,
I have a list of 6 DropDownList boxes, from DropDownList1 to
DropDownList6, and I'm changing the SelectedIndex of each using a
foreach loop as follows:
foreach(PaymentReqDisplay thispayment in listPaymentReqDisplay)
{
if ((string)thispayment.TaxType == "FIT")
this.DropDownList1.SelectedIndex =
(int)thispayment.PaymentRequirementID - 1;
if ((string)thispayment.TaxType == "FUI")
this.DropDownList2.SelectedIndex =
(int)thispayment.PaymentRequirementID - 1;
if ((string)thispayment.TaxType == "SIT")
this.DropDownList3.SelectedIndex =
(int)thispayment.PaymentRequirementID - 1;
if ((string)thispayment.TaxType == "SUI")
this.DropDownList4.SelectedIndex =
(int)thispayment.PaymentRequirementID - 1;
if ((string)thispayment.TaxType == "ETF")
this.DropDownList5.SelectedIndex =
(int)thispayment.PaymentRequirementID - 1;
if ((string)thispayment.TaxType == "SDI")
this.DropDownList6.SelectedIndex =
(int)thispayment.PaymentRequirementID - 1;
}
The problem is that when I change, say, DropDownList4.SelectedIndex =
3; every other DropDownList's SelectedIndex changes as well!?
What am I doing wrong?
Thanks much for your help.
Steve- Hide quoted text -

- Show quoted text -
So you are saying that by setting the SelectIndex of (say) the first
ddl ALL of the ddls in that group get set along with it?
So how do I replicate the item collection for every single ddl? I
don't understand what you mean. Could you give me a code example?

Thanks so much for your help.
Steve

Nov 14 '07 #3

P: n/a
I mean every ddl should have it's own item collection, not shared with the
other ddls.

How do you populate the ddls?

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"S_K" <st***********@yahoo.comwrote in message
news:11*********************@22g2000hsm.googlegrou ps.com...
On Nov 14, 2:52 am, "Eliyahu Goldin"
<REMOVEALLCAPITALSeEgGoldD...@mMvVpPsS.orgwrote:
>Do all ddls share the same items?

When you set the SelectedIndex property, it actually sets the Selected
property of the item you select. Thus the same item becomes selected in
all
ddls it is participating.

The solution is to replicate the item collection for every single ddl.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP
[ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net

"S_K" <steve_kers...@yahoo.comwrote in message

news:11**********************@22g2000hsm.googlegr oups.com...
Hi,
I have a list of 6 DropDownList boxes, from DropDownList1 to
DropDownList6, and I'm changing the SelectedIndex of each using a
foreach loop as follows:
foreach(PaymentReqDisplay thispayment in listPaymentReqDisplay)
{
if ((string)thispayment.TaxType == "FIT")
this.DropDownList1.SelectedIndex =
(int)thispayment.PaymentRequirementID - 1;
if ((string)thispayment.TaxType == "FUI")
this.DropDownList2.SelectedIndex =
(int)thispayment.PaymentRequirementID - 1;
if ((string)thispayment.TaxType == "SIT")
this.DropDownList3.SelectedIndex =
(int)thispayment.PaymentRequirementID - 1;
if ((string)thispayment.TaxType == "SUI")
this.DropDownList4.SelectedIndex =
(int)thispayment.PaymentRequirementID - 1;
if ((string)thispayment.TaxType == "ETF")
this.DropDownList5.SelectedIndex =
(int)thispayment.PaymentRequirementID - 1;
if ((string)thispayment.TaxType == "SDI")
this.DropDownList6.SelectedIndex =
(int)thispayment.PaymentRequirementID - 1;
}
The problem is that when I change, say, DropDownList4.SelectedIndex =
3; every other DropDownList's SelectedIndex changes as well!?
What am I doing wrong?
Thanks much for your help.
Steve- Hide quoted text -

- Show quoted text -

So you are saying that by setting the SelectIndex of (say) the first
ddl ALL of the ddls in that group get set along with it?
So how do I replicate the item collection for every single ddl? I
don't understand what you mean. Could you give me a code example?

Thanks so much for your help.
Steve

Nov 14 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.