473,320 Members | 1,713 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

define CSS for ListItem in CheckBoxList programmatically

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);

Thanks a lot.

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

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(EventArgs e)
{
ListItem item = new ListItem();
item.Text = "<span class=\"CheckBox\">Three</span>";
item.Value = "Three";
this.CheckBoxList1.Items.Add(item);
}
</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:checkboxlist id="CheckBoxList1" runat="server" cssclass="CheckBoxList">
<asp:listitem value="One">One</asp:listitem>
<asp:listitem value="Two">Two</asp:listitem>
</asp:checkboxlist>
</form>
</body>
</html>
"Shaul Feldman" <sf******@writeme.com> wrote in message news:OX**************@TK2MSFTNGP11.phx.gbl...
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);

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 "CheckBoxList" 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**************@TK2MSFTNGP11.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(EventArgs e)
{
ListItem item = new ListItem();
item.Text = "<span class=\"CheckBox\">Three</span>";
item.Value = "Three";
this.CheckBoxList1.Items.Add(item);
}
</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:checkboxlist id="CheckBoxList1" runat="server" cssclass="CheckBoxList"> <asp:listitem value="One">One</asp:listitem>
<asp:listitem value="Two">Two</asp:listitem>
</asp:checkboxlist>
</form>
</body>
</html>
"Shaul Feldman" <sf******@writeme.com> wrote in message

news:OX**************@TK2MSFTNGP11.phx.gbl...
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);

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="CheckBoxList". So,

<Foobar class="CheckBoxList"> ... <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******@writeme.com> wrote in message news:ef**************@TK2MSFTNGP10.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 "CheckBoxList" 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**************@TK2MSFTNGP11.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(EventArgs e)
{
ListItem item = new ListItem();
item.Text = "<span class=\"CheckBox\">Three</span>";
item.Value = "Three";
this.CheckBoxList1.Items.Add(item);
}
</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:checkboxlist id="CheckBoxList1" runat="server" cssclass="CheckBoxList"> <asp:listitem value="One">One</asp:listitem>
<asp:listitem value="Two">Two</asp:listitem>
</asp:checkboxlist>
</form>
</body>
</html>
"Shaul Feldman" <sf******@writeme.com> wrote in message

news:OX**************@TK2MSFTNGP11.phx.gbl...
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);

Thanks a lot.

--
With the best wishes,
Shaul Feldman


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

--
With the best wishes,
Shaul Feldman

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

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

<Foobar class="CheckBoxList"> ... <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******@writeme.com> wrote in message news:ef**************@TK2MSFTNGP10.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 "CheckBoxList" 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**************@TK2MSFTNGP11.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(EventArgs e)
{
ListItem item = new ListItem();
item.Text = "<span class=\"CheckBox\">Three</span>";
item.Value = "Three";
this.CheckBoxList1.Items.Add(item);
}
</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:checkboxlist id="CheckBoxList1" runat="server" cssclass="CheckBoxList"> <asp:listitem value="One">One</asp:listitem>
<asp:listitem value="Two">Two</asp:listitem>
</asp:checkboxlist>
</form>
</body>
</html>
"Shaul Feldman" <sf******@writeme.com> wrote in message

news:OX**************@TK2MSFTNGP11.phx.gbl...
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);

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
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...
4
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...
4
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...
3
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...
2
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...
7
by: bienwell | last post by:
Hi, I'm using the CheckBoxList control in ASP.NET for Web development. This checkboxlist is bound by the database. If we have more items for this checkbox list, it takes space on the page. I...
4
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. ...
4
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...
0
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 =...
2
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.