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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

asp:dropdownlist problem 1

Status
Not open for further replies.

dhmfh

Programmer
Nov 28, 2005
69
GB
Hi guys.

Does anyone know how to align the text in the drop down box to the right? I have assigned a CssClass to the control and for some reason it doesn't work?

Any ideas
 
i dont think this can be done, as style cannot be applied to the items of a dropdownlist. you may however try looking at other options (like using JS)...

Known is handfull, Unknown is worldfull
 
style cannot be applied to the items of a dropdownlist
It can't be applied using the CssClass item of the ListItem but you can still easily apply any style by referencing the items directly from your CSS file.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
>>but you can still easily apply any style by referencing the items directly from your CSS file


i dont get you, can i have a sample?

Known is handfull, Unknown is worldfull
 
In you CSS file, just reference the actual item. e.g. if your DropDownList was called myList you could use:
Code:
#myList ul li
{
 ...
}


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
>>In you CSS file, just reference the actual item. e.g. if your DropDownList was called myList you could use

but can you apply the same to the items of the list?

that is NOT possible.

this is the example that i tried:
Code:
<style>
#myList ul li
{
 color:red;
};
.txt{color:red;}

</style>
<select id=myList>
	<option>asdsa</option>
</select>
<div class="txt">Red</div>

the poster wants to change the style of "asdsa", i.e. the content of the dropdown...

Known is handfull, Unknown is worldfull
 
Yes, that work as you've referenced a ul and li tag but then used an option element (my example was simply to show you can reference any element in CSS). To make your example work, you could have used a few methods including:
Code:
<html>
<head>
<style type="text/css">
#option1{background-color:Red; color:White}
#option2{color:Red}
</style>
</head>
<body>

<select>
  <option id="option1">Option 1</option>
  <option id="option2">Option 2</option>
</select>

</body>
</html>


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
brilliant!

never thought that could be done,

however, how do u change the alignment. i tried this:
Code:
<html>
<head>
<style type="text/css">
#option1{background-color:green; color:White;text-align: center}
</style>
</head>
<body>

<select style="width:150px">
  <option id="option1">Option 1</option>
  <option id="option1">Option 2</option>
</select>

</body>
</html>

Known is handfull, Unknown is worldfull
 
It may not have worked in your example as you have two id's with the same name. This seemed to work fine for me:
Code:
<html>
<head>
<style type="text/css">
#option1{background-color:Red; color:White; text-align: center;}
#option2{color:Red; text-align: center;}
</style>
</head>
<body>

<select>
  <option id="option1">Option 1</option>
  <option id="option2">Option 2</option>
</select>

</body>
</html>


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
>>two id's with the same name

i did that wantonly as the other attributes were applying.
i did that because otherwise how dow we write code to use it?

as:
1. I cannot add different Ids to each option
2. How do i even generate different Ids for each entry?


Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top