Re: Why can't I set the listbox selectedIndex to -1?



this can only be done in javascript. in html if you render a select with no option set as selected, it defaults to the first. in javascript you can set the selectedIndex to -1 which will unselect.

you can subclass the listbox, and have it generate the required javascript.

-- bruce (sqlwork.com)

amtamayo@xxxxxxxxx wrote:
I have a simple webform that has a listbox that I bind to a dataview
at designtime. This provides an optional selection for the user so I
wanted to have no default value selected. So on the Page_Load event,
I set the selectedIndex to -1. However, when I run the page, the
default value is still 0, which forces the first item to be
automatically selected. I tried a bunch of things. I tried setting
it to 0, then -1. I tried to call ClearSelection() then set it to -1,
but no avail. This is a listbox, for crying out loud! This ought to
be simple, but is not.

Need help.

.



Relevant Pages

  • Problem moving items between two html select objects
    ... select object(listbox) before the selected item in the second listbox. ... selectedindex property of the second listbox, but it is always -1 even ... If I hardcode a number, rather than using toIndex, then the ... this is in an asp project where I am generating the javascript ...
    (microsoft.public.scripting.jscript)
  • Re: Changing a variable value based on pull down menu value
    ... and using the selectedIndex property. ... >>> You can debug JavaScript! ... >>> which comes with Microsoft Script Debugger. ... Now, in an HTML document, HTML elements ...
    (microsoft.public.frontpage.programming)
  • Re: Advanced javascript - can anyone explain this intricacy?
    ... Javascript Professional Projects - there is a fragment ... OPTION element from the SELECT element. ... so the - selectedIndex - property of the SELECT element ... them triggered by the side-effect code in the 'setters'. ...
    (comp.lang.javascript)
  • Re: retain last select option value
    ... task, but it adds a lot of overhead and I would like to move the overhead to the remote client's PC, using javascript. ... However, you might be able to design your page so that if javascript is available and has support for suitable features, you can perhaps skip a trip to the server. ... The selected option of a select element is given by the selectedIndex ...
    (comp.lang.javascript)
  • Re: Advanced javascript - can anyone explain this intricacy?
    ... In javascript -1 equates to null, and null can equate to false. ... selectedIndex property should return -1. ...
    (comp.lang.javascript)

Loading