473,546 Members | 2,249 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem changing the selected index property on a dropdown control

Hi all,

Am I being really stupid here:

myDropDown.Sele ctedIndex = 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 1852
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@micro softs_free_emai l_service.com> wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..
Hi all,

Am I being really stupid here:

myDropDown.Sele ctedIndex = 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******** ******@TK2MSFTN GP10.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@micro softs_free_emai l_service.com> wrote in
message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..
Hi all,

Am I being really stupid here:

myDropDown.Sele ctedIndex = 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@micro softs_free_emai l_service.com> wrote in message
news:eE******** *****@TK2MSFTNG P12.phx.gbl...
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:Ol******** ******@TK2MSFTN GP10.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@micro softs_free_emai l_service.com> wrote in
message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..
Hi all,

Am I being really stupid here:

myDropDown.Sele ctedIndex = 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
4274
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 value="1">Martin</option> <option value="2">Chris</option> <option value="5">adrian</option> <option value="7">Tony</option>
5
10805
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. I have tried setting various values to represent the default value with little success. Essentially I am looking to have the first item in the list...
12
3968
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 SelectedIndexChanged event. However, when I go back to this control again and select the first item in the list, it does a postback and the...
3
2048
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
4534
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 set to...it is set to false. Can someone show me what I am doing wrong and tell me the correct way? Thank you. In the page load event, I am...
1
2063
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 a listbox.selecteditem. When a different item is selected in the listbox, all the fields are repopulated with the correct data. I have 1...
3
1643
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 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...
4
2100
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 dropdown index it returns zero .. What is the problem ? private void Page_Load(object sender, System.EventArgs e) { int TotalP=0;
2
1560
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 created the database and accessed various ASP.NET 2.0 admin web pages for populating some of the fields. The issue is, on one particular page that has...
0
7504
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7694
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7461
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7792
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5080
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3491
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3470
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1921
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
747
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.