Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Problem changing the selected index property on a dropdown control

Reply
Thread Tools

Problem changing the selected index property on a dropdown control

 
 
Simon Harvey
Guest
Posts: n/a
 
      11-15-2004
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


 
Reply With Quote
 
 
 
 
Karl Seguin
Guest
Posts: n/a
 
      11-15-2004
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:%(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
 
 
 
Simon Harvey
Guest
Posts: n/a
 
      11-15-2004
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:(E-Mail Removed)...
> 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:%(E-Mail Removed)...
>> 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


 
Reply With Quote
 
Karl Seguin
Guest
Posts: n/a
 
      11-15-2004
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:(E-Mail Removed)...
> "Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
> wrote in message news:(E-Mail Removed)...
> > 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:%(E-Mail Removed)...
> >> 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
>
>



 
Reply With Quote
 
Simon Harvey
Guest
Posts: n/a
 
      11-15-2004
> "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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
need help to fill textboxes from a selected item in datagrid-selected index changed. mldardy ASP .Net 0 09-28-2010 02:59 PM
dropdown losing selected index value Steve Hershoff ASP .Net Datagrid Control 0 11-10-2006 07:34 PM
custom dropdown problems keeping selected index and lisitems jason.hau@gmail.com ASP .Net 0 09-01-2006 03:31 PM
bind a dropdown in a column in a datagrid based on the dropdown value selected in another column of the datagrid. vishnu ASP .Net 1 03-25-2006 01:24 PM
Problem changing the selected index property on a dropdown control Simon Harvey ASP .Net 4 11-15-2004 04:57 PM



Advertisments