473,320 Members | 1,900 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,320 software developers and data experts.

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 1844
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: martin | last post by:
Hi, I have a dropdown control tha is rendered with the follwoing HTML <select name="FirstStep:CmbTargetGroup" id="FirstStep_CmbTargetGroup" style="width:152px;"> <option...
5
by: Kris Rockwell | last post by:
Hello (again), I have gotten the dropdown list functionality to work through a few tricks (probably not the most efficient, but it works) but I am not sure how to set the default selected value....
12
by: moondaddy | last post by:
I have a dropdown combo box on a form and I have its AutoPostBack property set to true. When I select something from the list it does a postback and then the Page_Load event fires followed by it's...
3
by: msnews.microsoft.com | last post by:
Hi All, I m facing problem in Server Side Validation. For Example The Scenario is I have two fields on the page 1 Country Dropdown List 2 Province Textbox 3 State Dropdown List
2
by: Mike Collins | last post by:
I cannot get the correct drop down list value from a drop down I have on my web form. I get the initial value that was loaded in the list. It was asked by someone else what the autopostback was...
1
by: amber | last post by:
I'm having an issue with a combobox that is making no sense to me at all. I have a form with several comboboxes/textboxes. The values in these boxes are based on a datarowview, which is based on...
3
by: RSH | last post by:
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...
4
by: in da club | last post by:
I have a datagrid and a dropdown in my page. I want to fill dropdown with my pagenumbers. When a user change the dropdown selected index i wnt to display the result on label1. Anytime i change the...
2
by: dm3281 | last post by:
Hi all -- I have a strange issue. I have obtained a scripted database and compiled ASP.NET 2.0 application from a sister site that I'm trying to implement locally. I have successfully...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
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: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.