473,626 Members | 3,467 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 1269
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
3072
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
1110
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
5658
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
1546
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
4645
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
6159
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
1337
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
4572
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
8268
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
8202
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8707
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
7199
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6125
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5575
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
4093
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4202
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1812
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.