DropDowns: Setting index

Discussion in 'ASP .Net Web Controls' started by SJ, Oct 24, 2005.

  1. SJ

    SJ Guest

    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
     
    SJ, Oct 24, 2005
    #1
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. KathyB
    Replies:
    6
    Views:
    701
    Todd Thompson
    Jun 27, 2003
  2. Paul

    DropDowns... another one.

    Paul, Jul 14, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    512
  3. SJ

    dropdowns:setting index

    SJ, Oct 24, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    453
  4. karthikeyavenkat
    Replies:
    2
    Views:
    994
    Bryce
    Mar 17, 2005
  5. Shawn W_
    Replies:
    5
    Views:
    573
    Aldric Giacomoni
    Sep 16, 2009
  6. ngoc
    Replies:
    5
    Views:
    403
    Tad McClellan
    May 11, 2006
  7. Tomasz Chmielewski

    sorting index-15, index-9, index-110 "the human way"?

    Tomasz Chmielewski, Mar 4, 2008, in forum: Perl Misc
    Replies:
    4
    Views:
    621
    Tomasz Chmielewski
    Mar 4, 2008
  8. Stefan Mueller
    Replies:
    7
    Views:
    371
    Thomas 'PointedEars' Lahn
    Nov 28, 2005
Loading...