Remove default value from asp:dropdownlist

A place to discuss the implementation and style of computer programs.

Moderators: phlip, Moderators General, Prelates

Remove default value from asp:dropdownlist

Postby b1ackcat » Mon Mar 19, 2012 2:26 pm UTC

Hey all,

I have an asp:dropdownlist that I'm going to be applying some styling to. What I'm hoping to figure out how to do is have the dropdown list show a default value, like "--select--" or something, but then when you click to drop the list down, that "--select--" should NOT appear in the list.

I have the default text appearing fine, but I want it to only show up as the 'presentation' of the list, not actually be a part of the list. Is there a way to set this up?
My favorite Churchill quote: "The best argument against democracy is a five-minute conversation with the average voter."
User avatar
b1ackcat
 
Posts: 274
Joined: Mon Oct 20, 2008 4:35 pm UTC

Re: Remove default value from asp:dropdownlist

Postby papasound » Tue Mar 20, 2012 4:02 pm UTC

you have to add clientside trigger to asp:DropDownList onclick="javascript:x=this.options[0];(x.value=='triggervalue')?this.removeChild(x):false"
and first node would be
<asp:ListItem Text="--Select--" Value="triggervalue"/>

i can't test it on my rig, but i think it's the way to go.
papasound
 
Posts: 1
Joined: Tue Mar 20, 2012 12:49 pm UTC

Re: Remove default value from asp:dropdownlist

Postby b1ackcat » Wed Mar 21, 2012 3:48 pm UTC

Close, but not quite. This removes it from the list permanently. The functionality I'm looking for would have the item still remain but only as the top of the list. It's more of a menu than a dropdown. I've found a way to implement it using lists, but thanks for your help.
My favorite Churchill quote: "The best argument against democracy is a five-minute conversation with the average voter."
User avatar
b1ackcat
 
Posts: 274
Joined: Mon Oct 20, 2008 4:35 pm UTC

Re: Remove default value from asp:dropdownlist

Postby darkone238 » Wed Apr 04, 2012 10:51 pm UTC

Could you please elaborate on the solution you found? I actually have an application for such functionality and I ended up dealing with it a hacky way. I'd very much appreciate it :)
User avatar
darkone238
 
Posts: 68
Joined: Thu Feb 09, 2012 6:37 am UTC


Return to Coding

Who is online

Users browsing this forum: No registered users and 8 guests