Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DropDownList ListItem Text Being Replaced

Status
Not open for further replies.

jgd123456

Programmer
Nov 3, 2006
19
GB
Hi, I have the following code on my page:

<asp:DropDownList ...>
<asp:ListItem Value=""> &nbps; Test</asp:ListItem>
</asp:DropDownList>

but &nbps; keeps getting replaced (i understand this is for security reasons). I read once how you could create your own control inherting from the DropDownList which changes the way the DropDownList renders the text property within the ListItem (so that no replaces are made) but i seemed to have misplaced it and would appreciate if someone could point me in the right direction.

Thanks
 
just curious, why do you need the whitespace at all? are you trying to format the dropdown list items. if so use css. CSS isn't my strongest skill but something like this may work
Code:
[COLOR=green]/* option 1 */[/color]
select option { align: right; }
[COLOR=green]/* option 2 */[/color]
select.formatted option { align: right; }
[COLOR=green]/* option 3 */[/color]
option.formatted { align: right; }
option 1: applies to all dropdown and listbox controls.
option 2: applies to all options within a dropdownlist or listbox with a class of [tt]formatted[/tt].
option 3: applies to all ListItems with a class of [tt]formatted.[/tt]

by default ListItems don't have a CSSClass property, so you would need to add this in code behind if you wanted to apply the formatting to specific options only.
Code:
foreach(ListItem item in myDropDown.Items)
{
   item.Attributes.Add("css", "formatted");
}

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Hi, sorry i just chucked the code above together as an example (untested). I found the post that helped now. I had to override the Render method by extending the DropDownList control. The problem i had is that i wished to use the DropDownList to select a category (which has a parentid) so the data becomes hierachical eg:

Cat 1
Sub 1
Sub 2
Sub 2 Sub 1
Sub 3
Cat 2
...

But whenever i did &nbsp; within the text part it was getting replaced. All is resolved now though. Thanks anywayz.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top