DropDowns: Setting index

S

SJ

Hi,

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

myWebFile.aspx has the following code :

<asp:DropDownList id=test runat=server />
<asp:DropDownList 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.ToString(), i.ToString()));
test2.Items.Add(new ListItem(i.ToString(), i.ToString()));
}

And finally setting the selected value like this :

test.SelectedIndex = 1;
test2.SelectedIndex = 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
 

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

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top