473,714 Members | 2,500 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

dropdowns:setti ng index

SJ
Hi,

i'm trying to use codebehind to setup my dropdowns.

myWebFile.aspx has the following code :

<asp:DropDownLi st id=test runat=server />
<asp:DropDownLi st id=test2 runat=server />

And i'm defining the ListItems like this in codebehind:

for(int i=0;i<3;i++)
{
test.Items.Add( new ListItem(i.ToSt ring(), i.ToString()));
test2.Items.Add (new ListItem(i.ToSt ring(), i.ToString()));
}

And finally setting the selected index like this :

test.SelectedIn dex = 1;
test2.SelectedI ndex = 2;

Except the code above doesnt work as expected and sets BOTH test and test2
with a SelectedIndex of 2.
Any ideas why this would happen?

thanks
-SJ

Nov 19 '05 #1
2 1272
IIRC it's because when you set the SelectedIndex it goes back to the source
of the list, which is the ListItem collection and since they both use the
same one it sets the source's index....
That's my guess.....you may want to declare the ListItem object twice, with
2 names, and add seperatly?

--
Curt Christianson
site: http://www.darkfalz.com
blog: http://blog.darkfalz.com

"SJ" wrote:
Hi,

i'm trying to use codebehind to setup my dropdowns.

myWebFile.aspx has the following code :

<asp:DropDownLi st id=test runat=server />
<asp:DropDownLi st id=test2 runat=server />

And i'm defining the ListItems like this in codebehind:

for(int i=0;i<3;i++)
{
test.Items.Add( new ListItem(i.ToSt ring(), i.ToString()));
test2.Items.Add (new ListItem(i.ToSt ring(), i.ToString()));
}

And finally setting the selected index like this :

test.SelectedIn dex = 1;
test2.SelectedI ndex = 2;

Except the code above doesnt work as expected and sets BOTH test and test2
with a SelectedIndex of 2.
Any ideas why this would happen?

thanks
-SJ


Nov 19 '05 #2
SJ
That fixed it.
thanks!

-SJ.

"Curt_C [MVP]" <software_at_da rkfalz.com> wrote in message
news:AA******** *************** ***********@mic rosoft.com...
IIRC it's because when you set the SelectedIndex it goes back to the source of the list, which is the ListItem collection and since they both use the
same one it sets the source's index....
That's my guess.....you may want to declare the ListItem object twice, with 2 names, and add seperatly?

--
Curt Christianson
site: http://www.darkfalz.com
blog: http://blog.darkfalz.com

"SJ" wrote:
Hi,

i'm trying to use codebehind to setup my dropdowns.

myWebFile.aspx has the following code :

<asp:DropDownLi st id=test runat=server />
<asp:DropDownLi st id=test2 runat=server />

And i'm defining the ListItems like this in codebehind:

for(int i=0;i<3;i++)
{
test.Items.Add( new ListItem(i.ToSt ring(), i.ToString()));
test2.Items.Add (new ListItem(i.ToSt ring(), i.ToString()));
}

And finally setting the selected index like this :

test.SelectedIn dex = 1;
test2.SelectedI ndex = 2;

Except the code above doesnt work as expected and sets BOTH test and test2 with a SelectedIndex of 2.
Any ideas why this would happen?

thanks
-SJ


Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

23
3076
by: Ash | last post by:
Hi everyone, This problem has been puzzling me for a fair time now, and has severely frustrated me!! Perhaps I'm just not getting the syntax right, but the problem is rather simple... Take a look at: http://www.gasthofreiner.com/ The small booking form on the left, we're using the same one, but we need to
0
1113
by: Marc Miller | last post by:
Hi to all, (I apologize that I posted this in dotnet.languages.vb.controls, but I NEED and answer quickly, please) I have an 'employees' datagrid which contains company numbers as labels. When the user clicks 'Update', I have dropdown lists as edititems for the company numbers and populate them from a company table so that the user can change the existing company number. The problem is that the
6
5663
by: KathyB | last post by:
Hi, On Page Load (if not postback), the user selects a choice from dropdownlist1. On SelectedItemChanged for dropdownlist1, dropdownlist2 is populated and the user selects an item. I cannot find a combination where I can RETAIN both values during postback...if I put if not posback on the change event of
3
1548
by: Jon | last post by:
I am using cascading dropdowns, where one dropdown determines the data in the next, etc... If a dropdown has only one item in it, the SelectedIndexChanged event is never fired, even if you click on the dropdown and "reselect" the single item. This also happens when there are multiple items in the DD with the first item. You have to select another list item, then reselect the first one to have the event fire. I have it set to...
7
1520
by: segal.aviad | last post by:
Hi, I'm trying to write a web page containing three dropdowns. The dropdowns are declared as follows: <asp:DropDownList id="cmbCat1" runat="server" AutoPostBack="true"></asp:DropDownList> <asp:DropDownList id="cmbCat2" runat="server" AutoPostBack="True"></asp:DropDownList> <asp:DropDownList id="cmbCat3" runat="server"
0
4646
by: nkparimi | last post by:
Hi, Here's what I'm trying: given an html table, to freeze the column headers and/or left column in IE. I understand that this is possible thru style sheets in IE, as suggested in the following: http://web.tampabay.rr.com/bmerkey/examples/locked-column-csv.html http://www.adp-gmbh.ch/web/css/expression.html
64
6403
by: Manfred Kooistra | last post by:
I am building a website with identical content in four different languages. On a first visit, the search engine determines the language of the content by the IP address of the visitor. What the user sees is content in only one language at a time. He or she can then switch to another language and set this as the preferred language, but again he or she sees content in only this one other language. The question now is: How do I get search...
7
1338
by: surikumarvinod | last post by:
hello, I have a page in wich i have 3 dropdowns and a grid view. when i click on the edit button in grid view to update a record it takes me to edit page. what i want is when i come back from the edit page back to the page with grid view and the dropdowns. The selected index of the dropdowns should be the same as when i clicked the edit button. Tell me some solution without using session, querystring or cookies. Vinod Suri.
4
4586
by: zion4ever | last post by:
Hello good people, Please bear with me as this is my first post and I am relative new to ASP. I do have VB6 experience. I have a form which enables users within our company to do an intranet reservation of available resources (laptops, beamers, etc). The MySql database queries are already in place, as is the ASP administration panel. The frontend that users will see however, still needs some work. I'm really close, but since I'm no...
0
8801
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9314
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9174
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9074
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
9015
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5947
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4725
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3158
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
2
2520
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.