Problem changing the selected index property on a dropdown control

S

Simon Harvey

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
 
K

Karl Seguin

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
 
S

Simon Harvey

Karl Seguin said:
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/


message


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
 
K

Karl Seguin

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
 
S

Simon Harvey

"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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top