473,788 Members | 2,837 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

define CSS for ListItem in CheckBoxList programmaticall y

Hello,
I have something really awkward at work - fighting with CheckBoxList...
How can I define CSS for ListItem in CheckBoxList programmaticall y.
I add CheckBoxList's Items on the fly, something like

dim li as ListItem
li = new ListItem("title ","value");
'' how to define here the CSS for List Item, not CheckBoxList?!? !?!
myCheckBoxList. Items(x).add(li );

Thanks a lot.

--
With the best wishes,
Shaul Feldman
Nov 18 '05 #1
4 6531

There are two approaches I can think of; one is to define an external style selector; it will be tricky since CheckBoxList will
render it's HTML differently depending on the browser -- for uplevel browsers you'll get a <input><label > and you can exploit that
with a CSS selector that looks like:

..CssForListBox label {
color: red;
}

The other approach is to create a <span> around the ListItem Text and attach a style/class to that. See the sample below.
Scott

<%@ Page language="c#" AutoEventWireup ="false" trace="true" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html>
<head>
<script language="C#" runat="server">
protected override void OnLoad(EventArg s e)
{
ListItem item = new ListItem();
item.Text = "<span class=\"CheckBo x\">Three</span>";
item.Value = "Three";
this.CheckBoxLi st1.Items.Add(i tem);
}
</script>
<style>
..CheckBoxList
{
font-weight: bold;
font-family: Tahoma, Verdana, 'Times New Roman';
}
..CheckBoxList label
{
color:red;
}

..CheckBox {
color: blue;
}
</style>
</head>
<body>
<form id="Form1" method="post" runat="server">
<asp:checkboxli st id="CheckBoxLis t1" runat="server" cssclass="Check BoxList">
<asp:listitem value="One">One </asp:listitem>
<asp:listitem value="Two">Two </asp:listitem>
</asp:checkboxlis t>
</form>
</body>
</html>
"Shaul Feldman" <sf******@write me.com> wrote in message news:OX******** ******@TK2MSFTN GP11.phx.gbl...
Hello,
I have something really awkward at work - fighting with CheckBoxList...
How can I define CSS for ListItem in CheckBoxList programmaticall y.
I add CheckBoxList's Items on the fly, something like

dim li as ListItem
li = new ListItem("title ","value");
'' how to define here the CSS for List Item, not CheckBoxList?!? !?!
myCheckBoxList. Items(x).add(li );

Thanks a lot.

--
With the best wishes,
Shaul Feldman

Nov 18 '05 #2
Ok,
I think I got the picture...
The question (not quiet ASP.Net, but still) is when you declare
..CheckBoxList label
{
color:red;
}
it means all label instances UNDER elemnets of "CheckBoxLi st" class will be
colored in red, I'm I right? In case I'm wrong, explain it please. Thanks.
Another question why can't be CSS assigned directly to ListItem object?...
It would fit the general concept quiet well.

--
With the best wishes,
Shaul Feldman

"Scott" <no*****@this-is-extra-hotmail.com> wrote in message
news:e2******** ******@TK2MSFTN GP11.phx.gbl...

There are two approaches I can think of; one is to define an external style selector; it will be tricky since CheckBoxList will render it's HTML differently depending on the browser -- for uplevel browsers you'll get a <input><label > and you can exploit that with a CSS selector that looks like:

.CssForListBox label {
color: red;
}

The other approach is to create a <span> around the ListItem Text and attach a style/class to that. See the sample below.

Scott

<%@ Page language="c#" AutoEventWireup ="false" trace="true" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html>
<head>
<script language="C#" runat="server">
protected override void OnLoad(EventArg s e)
{
ListItem item = new ListItem();
item.Text = "<span class=\"CheckBo x\">Three</span>";
item.Value = "Three";
this.CheckBoxLi st1.Items.Add(i tem);
}
</script>
<style>
.CheckBoxList
{
font-weight: bold;
font-family: Tahoma, Verdana, 'Times New Roman';
}
.CheckBoxList label
{
color:red;
}

.CheckBox {
color: blue;
}
</style>
</head>
<body>
<form id="Form1" method="post" runat="server">
<asp:checkboxli st id="CheckBoxLis t1" runat="server" cssclass="Check BoxList"> <asp:listitem value="One">One </asp:listitem>
<asp:listitem value="Two">Two </asp:listitem>
</asp:checkboxlis t>
</form>
</body>
</html>
"Shaul Feldman" <sf******@write me.com> wrote in message

news:OX******** ******@TK2MSFTN GP11.phx.gbl...
Hello,
I have something really awkward at work - fighting with CheckBoxList...
How can I define CSS for ListItem in CheckBoxList programmaticall y.
I add CheckBoxList's Items on the fly, something like

dim li as ListItem
li = new ListItem("title ","value");
'' how to define here the CSS for List Item, not CheckBoxList?!? !?!
myCheckBoxList. Items(x).add(li );

Thanks a lot.

--
With the best wishes,
Shaul Feldman


Nov 18 '05 #3

..CheckBoxList label {} Means all <label> elements below any element with a class="CheckBox List". So,

<Foobar class="CheckBox List"> ... <label></label></Foobar>

Don't have an answer as to why the individual ListItems can't get a style/class; but if you want a different style for each ListItem the <span style="..."></span> idea will do the same thing.

Scott

"Shaul Feldman" <sf******@write me.com> wrote in message news:ef******** ******@TK2MSFTN GP10.phx.gbl...
Ok,
I think I got the picture...
The question (not quiet ASP.Net, but still) is when you declare
.CheckBoxList label
{
color:red;
}
it means all label instances UNDER elemnets of "CheckBoxLi st" class will be
colored in red, I'm I right? In case I'm wrong, explain it please. Thanks.
Another question why can't be CSS assigned directly to ListItem object?...
It would fit the general concept quiet well.

--
With the best wishes,
Shaul Feldman

"Scott" <no*****@this-is-extra-hotmail.com> wrote in message
news:e2******** ******@TK2MSFTN GP11.phx.gbl...

There are two approaches I can think of; one is to define an external style selector; it will be tricky since CheckBoxList will render it's HTML differently depending on the browser -- for uplevel browsers you'll get a <input><label > and you can exploit that with a CSS selector that looks like:

.CssForListBox label {
color: red;
}

The other approach is to create a <span> around the ListItem Text and attach a style/class to that. See the sample below.

Scott

<%@ Page language="c#" AutoEventWireup ="false" trace="true" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html>
<head>
<script language="C#" runat="server">
protected override void OnLoad(EventArg s e)
{
ListItem item = new ListItem();
item.Text = "<span class=\"CheckBo x\">Three</span>";
item.Value = "Three";
this.CheckBoxLi st1.Items.Add(i tem);
}
</script>
<style>
.CheckBoxList
{
font-weight: bold;
font-family: Tahoma, Verdana, 'Times New Roman';
}
.CheckBoxList label
{
color:red;
}

.CheckBox {
color: blue;
}
</style>
</head>
<body>
<form id="Form1" method="post" runat="server">
<asp:checkboxli st id="CheckBoxLis t1" runat="server" cssclass="Check BoxList"> <asp:listitem value="One">One </asp:listitem>
<asp:listitem value="Two">Two </asp:listitem>
</asp:checkboxlis t>
</form>
</body>
</html>
"Shaul Feldman" <sf******@write me.com> wrote in message

news:OX******** ******@TK2MSFTN GP11.phx.gbl...
Hello,
I have something really awkward at work - fighting with CheckBoxList...
How can I define CSS for ListItem in CheckBoxList programmaticall y.
I add CheckBoxList's Items on the fly, something like

dim li as ListItem
li = new ListItem("title ","value");
'' how to define here the CSS for List Item, not CheckBoxList?!? !?!
myCheckBoxList. Items(x).add(li );

Thanks a lot.

--
With the best wishes,
Shaul Feldman


Nov 18 '05 #4
Thanks Scott!
Tomorrow I'll try the ".CheckBoxL ist label {} " patent.

--
With the best wishes,
Shaul Feldman

"Scott" <no*****@this-is-extra-hotmail.com> wrote in message news:uy******** *****@tk2msftng p13.phx.gbl...

.CheckBoxList label {} Means all <label> elements below any element with a class="CheckBox List". So,

<Foobar class="CheckBox List"> ... <label></label></Foobar>

Don't have an answer as to why the individual ListItems can't get a style/class; but if you want a different style for each ListItem the <span style="..."></span> idea will do the same thing.

Scott

"Shaul Feldman" <sf******@write me.com> wrote in message news:ef******** ******@TK2MSFTN GP10.phx.gbl...
Ok,
I think I got the picture...
The question (not quiet ASP.Net, but still) is when you declare
.CheckBoxList label
{
color:red;
}
it means all label instances UNDER elemnets of "CheckBoxLi st" class will be
colored in red, I'm I right? In case I'm wrong, explain it please. Thanks.
Another question why can't be CSS assigned directly to ListItem object?...
It would fit the general concept quiet well.

--
With the best wishes,
Shaul Feldman

"Scott" <no*****@this-is-extra-hotmail.com> wrote in message
news:e2******** ******@TK2MSFTN GP11.phx.gbl...

There are two approaches I can think of; one is to define an external style selector; it will be tricky since CheckBoxList will render it's HTML differently depending on the browser -- for uplevel browsers you'll get a <input><label > and you can exploit that with a CSS selector that looks like:

.CssForListBox label {
color: red;
}

The other approach is to create a <span> around the ListItem Text and attach a style/class to that. See the sample below.

Scott

<%@ Page language="c#" AutoEventWireup ="false" trace="true" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html>
<head>
<script language="C#" runat="server">
protected override void OnLoad(EventArg s e)
{
ListItem item = new ListItem();
item.Text = "<span class=\"CheckBo x\">Three</span>";
item.Value = "Three";
this.CheckBoxLi st1.Items.Add(i tem);
}
</script>
<style>
.CheckBoxList
{
font-weight: bold;
font-family: Tahoma, Verdana, 'Times New Roman';
}
.CheckBoxList label
{
color:red;
}

.CheckBox {
color: blue;
}
</style>
</head>
<body>
<form id="Form1" method="post" runat="server">
<asp:checkboxli st id="CheckBoxLis t1" runat="server" cssclass="Check BoxList"> <asp:listitem value="One">One </asp:listitem>
<asp:listitem value="Two">Two </asp:listitem>
</asp:checkboxlis t>
</form>
</body>
</html>
"Shaul Feldman" <sf******@write me.com> wrote in message

news:OX******** ******@TK2MSFTN GP11.phx.gbl...
Hello,
I have something really awkward at work - fighting with CheckBoxList...
How can I define CSS for ListItem in CheckBoxList programmaticall y.
I add CheckBoxList's Items on the fly, something like

dim li as ListItem
li = new ListItem("title ","value");
'' how to define here the CSS for List Item, not CheckBoxList?!? !?!
myCheckBoxList. Items(x).add(li );

Thanks a lot.

--
With the best wishes,
Shaul Feldman


Nov 18 '05 #5

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

Similar topics

3
5456
by: Robin Day | last post by:
I run some code on the changed event of checkbox lists. Its quite simple, nothing more than showing / hiding some other parts of the page. Using Autopostback and Server side code works fine, but is far too slow, especially if the users are on modems. I need to quite simply, add some java code to the onclick event of the input tags of a checkboxlist. However... Attributes.Add adds the onclick attribute and code to the outlying table that...
4
8073
by: dm_dal | last post by:
Is there a know issue surrounding the CheckBoxList control and it's viewstate? When my control is created, it's ListItems are checked as needed, but on a postback, they loose their Selected status. David
4
7733
by: Shaul Feldman | last post by:
Hello, I have something really awkward at work - fighting with CheckBoxList... How can I define CSS for ListItem in CheckBoxList programmatically. I add CheckBoxList's Items on the fly, something like dim li as ListItem li = new ListItem("title","value"); '' how to define here the CSS for List Item, not CheckBoxList?!?!?! myCheckBoxList.Items(x).add(li);
3
2922
by: I am Sam | last post by:
I keep getting the following error message when I try to iterate through a CheckBoxList control: Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.NullReferenceException: Object reference not set to an instance...
2
2128
by: Amelyan | last post by:
How can I assign an ID to dynamically generation ListItem that I add to dynamically generated CheckBoxList or RadioButtonList? I need to identify the specific ListItem later through Request.Form when user sends back data.
4
2901
by: Hong Yip | last post by:
Hi Everyone, I have an array of checkboxlist. Everything works prefectly fine until I start working on the "presentation" view. I am not able to "insert" a checkbox item to a table cell. Something like that, TableCell TCell = new TableCell();
4
4043
by: Patrick.O.Ige | last post by:
I have a CheckBoxList in a DataList and i'm trying to get item Selected after doing a postBack. I have set my CheckBoxlist AutoPostBack="True" Any ideas what 'm doing wrong? It seems not to work:( Thanks My CheckBoxList in the DataList Below
0
2030
by: CK | last post by:
Hi All, I have an asp:CheckBoxList. it is databound to a datatable at runtime; private void chklstStatuses_DataBinding(object sender, EventArgs e) { chklstStatuses.DataSource = BillingInvoiceUtil.GetStatuses(); chklstStatuses.DataTextField = "StatusName";
2
3865
by: clintonG | last post by:
When selected="true" is declared in the CheckBoxList ListItem FireFox does not display checked list items. Even more curious is the absence of the checked="checked" attribute in the source which is present and generated when the page is requested using IE. Confusing. Anything I can do? <%= Clinton Gallagher NET csgallagher AT metromilwaukee.com URL http://clintongallagher.metromilwaukee.com/
0
9656
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10366
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10175
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10112
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
9969
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8993
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7518
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6750
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4070
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

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.