Problem changing the selected index property on a dropdown control

Discussion in 'ASP .Net' started by Simon Harvey, Nov 15, 2004.

  1. Simon Harvey

    Simon Harvey Guest

    Hi all,

    Am I being really stupid here:

    myDropDown.SelectedIndex = 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
     
    Simon Harvey, Nov 15, 2004
    #1
    1. Advertising

  2. Simon Harvey

    Karl Seguin Guest

    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@microsofts_free_email_service.com> wrote in message
    news:%...
    > Hi all,
    >
    > Am I being really stupid here:
    >
    > myDropDown.SelectedIndex = 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
    >
    >
     
    Karl Seguin, Nov 15, 2004
    #2
    1. Advertising

  3. Simon Harvey

    Simon Harvey Guest

    "Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
    wrote in message news:...
    > 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@microsofts_free_email_service.com> wrote in
    > message
    > news:%...
    >> Hi all,
    >>
    >> Am I being really stupid here:
    >>
    >> myDropDown.SelectedIndex = 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
     
    Simon Harvey, Nov 15, 2004
    #3
  4. Simon Harvey

    Karl Seguin Guest

    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@microsofts_free_email_service.com> wrote in message
    news:...
    > "Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
    > wrote in message news:...
    > > 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@microsofts_free_email_service.com> wrote in
    > > message
    > > news:%...
    > >> Hi all,
    > >>
    > >> Am I being really stupid here:
    > >>
    > >> myDropDown.SelectedIndex = 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
    >
    >
     
    Karl Seguin, Nov 15, 2004
    #4
  5. Simon Harvey

    Simon Harvey Guest

    > "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
     
    Simon Harvey, Nov 15, 2004
    #5
    1. Advertising

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. vishnu
    Replies:
    1
    Views:
    1,251
    Patrick.O.Ige
    Mar 25, 2006
  2. Replies:
    0
    Views:
    363
  3. mldardy
    Replies:
    0
    Views:
    998
    mldardy
    Sep 28, 2010
  4. Steve Hershoff

    dropdown losing selected index value

    Steve Hershoff, Nov 10, 2006, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    753
    Steve Hershoff
    Nov 10, 2006
  5. Simon Harvey
    Replies:
    4
    Views:
    227
    Simon Harvey
    Nov 15, 2004
Loading...

Share This Page