470,586 Members | 1,297 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,586 developers. It's quick & easy.

Problem changing the selected index property on a dropdown control

Hi all,

Am I being really stupid here:

myDropDown.SelectedIndex = 2

I think this line should set the dropdown control's selected item to 2. But
nothing seems to be happening on the page. The dropdown just maintains its
default value (element 0).

Do I have to do something else to get this control to work? The only other
aspect that may be effecting this piece of code is the fact that the drop
down is contained within a user control that itself is contained in a user
control. But I don't see why that should matter.

Do I have to do something with viewstate or something tricky like that?

Many thanks to anyone who can help

Kindest Regards

Simon
Nov 18 '05 #1
4 1741
Everything looks fine. We'd need to see how you are populating your
dropdown with respect to that line? are you binding after? before? how are
you handling postback?

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Simon Harvey" <sh856531@microsofts_free_email_service.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Hi all,

Am I being really stupid here:

myDropDown.SelectedIndex = 2

I think this line should set the dropdown control's selected item to 2. But nothing seems to be happening on the page. The dropdown just maintains its
default value (element 0).

Do I have to do something else to get this control to work? The only other
aspect that may be effecting this piece of code is the fact that the drop
down is contained within a user control that itself is contained in a user
control. But I don't see why that should matter.

Do I have to do something with viewstate or something tricky like that?

Many thanks to anyone who can help

Kindest Regards

Simon

Nov 18 '05 #2
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:Ol**************@TK2MSFTNGP10.phx.gbl...
Everything looks fine. We'd need to see how you are populating your
dropdown with respect to that line? are you binding after? before? how
are
you handling postback?

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Simon Harvey" <sh856531@microsofts_free_email_service.com> wrote in
message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Hi all,

Am I being really stupid here:

myDropDown.SelectedIndex = 2

I think this line should set the dropdown control's selected item to 2.

But
nothing seems to be happening on the page. The dropdown just maintains
its
default value (element 0).

Do I have to do something else to get this control to work? The only
other
aspect that may be effecting this piece of code is the fact that the drop
down is contained within a user control that itself is contained in a
user
control. But I don't see why that should matter.

Do I have to do something with viewstate or something tricky like that?

Many thanks to anyone who can help

Kindest Regards

Simon

Hi Karl,

I don't do any databinding directly. At some point earlier in the program I
get a 2 ints representing a range, eg 1 5.
Then I do a loop and the following:

Grade 1
Grade 2
....
Grade 5

The problem occurs at somepoint after this. The control populates itself
fine, it just doesnt seem to do anything when I tell it what index to go to.
As for postback, I'm not actually doing a postback. This problem occurs when
loading the page for the very first time.

I wish I could show you some more code buts its actually really complicated
and all over the place because of the nature of the program.

Can you imagine why this would be happening. The only real thing i can think
of is that some other bit of code is running and reseting the value back to
0 before the page is sent to the browser. Do you think there is anything
else it could be?

Thanks

Simon
Nov 18 '05 #3
There could be timing issues...but I take it all of this is happening in
Page_Load ? I'm just thinking maybe you are setting the selectedIndex too
late (like after PreRender) but I doubt it...

"actually really complicated and all over the place because of the nature of
the program" << seems like your problem to me...

Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/
"Simon Harvey" <sh856531@microsofts_free_email_service.com> wrote in message
news:eE*************@TK2MSFTNGP12.phx.gbl...
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:Ol**************@TK2MSFTNGP10.phx.gbl...
Everything looks fine. We'd need to see how you are populating your
dropdown with respect to that line? are you binding after? before? how
are
you handling postback?

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Simon Harvey" <sh856531@microsofts_free_email_service.com> wrote in
message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Hi all,

Am I being really stupid here:

myDropDown.SelectedIndex = 2

I think this line should set the dropdown control's selected item to 2. But
nothing seems to be happening on the page. The dropdown just maintains
its
default value (element 0).

Do I have to do something else to get this control to work? The only
other
aspect that may be effecting this piece of code is the fact that the drop down is contained within a user control that itself is contained in a
user
control. But I don't see why that should matter.

Do I have to do something with viewstate or something tricky like that?

Many thanks to anyone who can help

Kindest Regards

Simon

Hi Karl,

I don't do any databinding directly. At some point earlier in the program

I get a 2 ints representing a range, eg 1 5.
Then I do a loop and the following:

Grade 1
Grade 2
...
Grade 5

The problem occurs at somepoint after this. The control populates itself
fine, it just doesnt seem to do anything when I tell it what index to go to. As for postback, I'm not actually doing a postback. This problem occurs when loading the page for the very first time.

I wish I could show you some more code buts its actually really complicated and all over the place because of the nature of the program.

Can you imagine why this would be happening. The only real thing i can think of is that some other bit of code is running and reseting the value back to 0 before the page is sent to the browser. Do you think there is anything
else it could be?

Thanks

Simon

Nov 18 '05 #4
> "actually really complicated and all over the place because of the nature
of
the program" << seems like your problem to me...


Yeah you're right, but theres nothing I can do about that right now I'm
afraid. I wish to hell I could

Simon
Nov 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Kris Rockwell | last post: by
12 posts views Thread by moondaddy | last post: by
3 posts views Thread by msnews.microsoft.com | last post: by
2 posts views Thread by Mike Collins | last post: by
1 post views Thread by amber | last post: by
4 posts views Thread by in da club | last post: by
2 posts views Thread by dm3281 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.