473,586 Members | 2,683 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Formatting a ListItem Control

I want to change the background color, font attributes, etc. of the choices
in my DropDownLists. When writing them using HTML SELECT and OPTION tags, I
can do something like the following:

<option
style="font-weight:bold;col or:green;backgr ound-color:purple;"> Displayed
Text</option>

but the ListItem Control does not have a Style property, which prevents me
from doing anything other than specifying the Text, Value, and Selected
properties. Is there any way to format the ListItem Control, such as some
kind of workaround (I know I could write my own Control that inherits
ListItem, but I have very little experience doing this, so I might do it in
the future, but for the moment I am looking for a workaround)?
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/
Nov 19 '05 #1
3 2395
Afternoon Nathan
Im not sure how frowned upon the practise of stylising individual options
within a select is but:
In the html code you could just add the style tag to the listitem
declaration (sure, its not there in intellisense but it should still show up
in ur broswer):
<asp:dropdownli st id="foo" runat="server">
<asp:listitem value="bar" style="backgrou nd: #000000;">Bar it
up</asp:listitem>
</asp:dropdownlis t>

or if you are using code to add items to the dropdownlist, then you could
add attributes to each listitem:
ListItem li = new ListItem();
li.Value = "bar";
li.Text = "Bar it up";
li.Attributes.A dd("style", "background : #000000;");
Foo.Items.Add(l i);

Also be aware that some css styles will not work when applied to
dropdownlists and possibly their child listitems.

Graham

"Nathan Sokalski" <nj********@hot mail.com> wrote in message
news:uz******** ******@TK2MSFTN GP09.phx.gbl...
I want to change the background color, font attributes, etc. of the choices
in my DropDownLists. When writing them using HTML SELECT and OPTION tags, I
can do something like the following:

<option
style="font-weight:bold;col or:green;backgr ound-color:purple;"> Displayed
Text</option>

but the ListItem Control does not have a Style property, which prevents me
from doing anything other than specifying the Text, Value, and Selected
properties. Is there any way to format the ListItem Control, such as some
kind of workaround (I know I could write my own Control that inherits
ListItem, but I have very little experience doing this, so I might do it
in the future, but for the moment I am looking for a workaround)?
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/

Nov 19 '05 #2
you can do it using a style sheet like this:

<html>
<head>

<style>
..DropDownList option
{
font-weight:bold;col or:green;backgr ound-color:purple;
}
</style>

</head>
<body>
<form runat="server">
<asp:DropDownLi st id="DropDownLis t1" runat="server"
CssClass="DropD ownList"></asp:DropDownLis t>
</form>
</body>
</html>

Nov 19 '05 #3
Nathan Sokalski wrote:
I want to change the background color, font attributes, etc. of the choices
in my DropDownLists. When writing them using HTML SELECT and OPTION tags, I
can do something like the following:

<option
style="font-weight:bold;col or:green;backgr ound-color:purple;"> Displayed
Text</option>

but the ListItem Control does not have a Style property, which prevents me
from doing anything other than specifying the Text, Value, and Selected
properties. Is there any way to format the ListItem Control, such as some
kind of workaround (I know I could write my own Control that inherits
ListItem, but I have very little experience doing this, so I might do it in
the future, but for the moment I am looking for a workaround)?


Nathan, this is a known problem with ListControls in ASP.NET 1.x. Check
oiut this article for a discussion as to WHY and a potential workaround.
(Although if all you want to do is styling, then the solution posted
by ne**********@gm ail.com is probably easier than my workaround at the
article below...)

ListControl Items and Attributes
http://aspnet.4guysfromrolla.com/articles/091405-1.aspx

Happy Programming!

--

Scott Mitchell [ASP.NET MVP]
mi******@4GuysF romRolla.com
http://www.4GuysFromRolla.com/ScottMitchell
Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1560
by: CGuy | last post by:
Hi, I have a RadioButtonList control in my aspx page which shows two radiobuttons - "Yes" and "No". Since my page is intended for international audience, I would like the texts "Yes" and "No" to be read from resource files. Right now, I'm doing it by the following code ListItem items = new ListItem{new...
3
5924
by: Jouke Langhout | last post by:
Hello all! For quite some time now, I've got the following problem: Access won't close properly when a user closes the application. An ACCESS process stays active and that process can only be terminated by pressing ++ and then terminate the process. I searched the entire internet and found out that there could be two things wrong (both...
4
4143
by: DBQueen | last post by:
I have a subform which is in Continuous Forms view. I have added a button to the bottom of the page to move to the next record using the button wizard (result: DoCmd.GoToRecord , , acNext). I want all of the controls in whatever is the CURRENT record to have it's data bolded on the screen. (Question #1: Is there a SIMPLE way to refer to...
7
17751
by: Amil | last post by:
Hi all, I am using VS 2005 Beta 2. Which assembly (namespace?) should I use for the ListItem class? I don't have the Help files installed on my notebook for space reasons; I use MSDN2 online instead. I see ListItem as derived from System.Web.UI.Controls namespace. Am I missing something here? I am creating a Windows application by the...
1
4927
by: Mike P | last post by:
How do I manage to format a radiobuttonlist so that if for example I have 3 options, I can put a text box to the right of each option? The radiobutton list doesn't seem to accept any html inbetween it which I would normally use for formatting (TR, TD etc). Any assistance would be much appreciated. Cheers,
4
1188
by: Angela | last post by:
Hi everyone, At the moment I am using the syntax of: <asp:radiobuttonlist id="rdDrive" runat="server" RepeatLayout="Table" RepeatColumns="2"> <asp:ListItem Value="1" text="Yes"></asp:ListItem> <asp:ListItem Value="0" text="No"></asp:ListItem> </asp:radiobuttonlist>
3
4782
by: Joey | last post by:
Hi, I'm trying to add a default item to my listbox but when I do it tells me that it's not defined, could someone tell me the syntax I need to use to get the listbox control to display a default item? I have tried the following: lstStates.Items.Insert(0, new ListItem("By State","0"))
8
3277
by: barry | last post by:
Have tried a number of things including space(n) in front of the string but when the DropDownList is shown the spaces have apparently been trimmed. Is this something that would have to be done in a custom control? I would like the spaces to be at the front end of the string " xxxxx". In vs.net I am doing a listitem(string) Any Help is...
1
1505
by: dbuchanan | last post by:
I want to fill a textbox or a label or with lines from a listbox. I want to preserve the lline for line as it comes from the list box. I do not want the test to run-on. I suppose it is okay to wrap if it is longer than the width of the control. This data will later be taken from this control and put into a text box in a report in...
0
7839
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8202
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7959
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8216
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6614
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5710
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5390
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2345
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.