473,480 Members | 1,968 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to style a CheckBoxList?

Has anybody figured out how to style this doohickey? I want to move the
label's text properties up so the text lines up with the checkbox itself.

<%= Clinton Gallagher

Dec 19 '05 #1
5 7751
Hi,

you need to check how it renders itself at client (probably with a <span> if
memory serves). Then you could had styles(heets) targeting that.

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke

"clintonG" <cs*********@REMOVETHISTEXTmetromilwaukee.com> wrote in message
news:ul*************@TK2MSFTNGP12.phx.gbl...
Has anybody figured out how to style this doohickey? I want to move the
label's text properties up so the text lines up with the checkbox itself.

<%= Clinton Gallagher

Dec 19 '05 #2
Hello Teemu,

If it was that easy I would have figured it out already but this control was
written by somebody evil.

The ListItems render as Label controls instead of text and as such they
properties are not accessible.
The ListItem is limited and only supports Enabled, Selected, Text and Value
properties. We can't use a SkinID or CSS directly on the label text but I
have found a hack that probably breaks XHTML validity...

// CheckBoxList ListItem Style Hack
<asp:ListItem Value="<span class='SkipDays'>Sunday</span>" />

Even this hack does not for some reason allow me to modify padding or
margins of the text and I don't know if it is going to affect getting the
values of the checked items yet.

In this case I need to collect one or more days of the week and if I use
this hack the collection returned may not be Sunday, Monday, Thursday but
<span class='SkipDays'>Sunday</span><span
class='SkipDays'>Monday</span><span class='SkipDays'>Thursday</span>

<%= Clinton Gallagher

"Teemu Keiski" <jo****@aspalliance.com> wrote in message
news:uS**************@TK2MSFTNGP15.phx.gbl...
Hi,

you need to check how it renders itself at client (probably with a <span>
if memory serves). Then you could had styles(heets) targeting that.

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke

"clintonG" <cs*********@REMOVETHISTEXTmetromilwaukee.com> wrote in message
news:ul*************@TK2MSFTNGP12.phx.gbl...
Has anybody figured out how to style this doohickey? I want to move the
label's text properties up so the text lines up with the checkbox itself.

<%= Clinton Gallagher


Dec 19 '05 #3
Your best bet is to ignore setting the text for your checkboxes and use
label controls instead. Then, if you're using a table for formatting, you
can use valign in the table cells to align your labels with your checkboxes,
though it probably won't be perfect depending on the browser. Different
browsers render the actual checkbox (fontwise) differently.

Hope this helps!
--
Christopher A. Reed
"The oxen are slow, but the earth is patient."

"clintonG" <cs*********@REMOVETHISTEXTmetromilwaukee.com> wrote in message
news:ul*************@TK2MSFTNGP12.phx.gbl...
Has anybody figured out how to style this doohickey? I want to move the
label's text properties up so the text lines up with the checkbox itself.

<%= Clinton Gallagher

Dec 21 '05 #4
Thanks for your comments Christopher but that raises an exception "The
'Text' property of 'asp:ListItem' does not allow child objects."

Apparently the problem is not so much the label and label text that the
ListItem generates but the TD that contains the label text. Ordinarily we
can use paddings and margins to overflow the text container to raise or
lower text a bit here and there as that's all that is ordinarily needed but
not in this case it seems.

I also see the checkbox control is still rendering as a bug which renders a
background color around the checkbox. I've forgotten exactly how to respond
to this IE bug. Do you know what property to modify? Again, as I recall it
was the TD background color properties but I can't remember.

<%= Clinton Gallagher

"Christopher Reed" <ca****@nospam.nospam> wrote in message
news:%2***************@TK2MSFTNGP11.phx.gbl...
Your best bet is to ignore setting the text for your checkboxes and use
label controls instead. Then, if you're using a table for formatting, you
can use valign in the table cells to align your labels with your
checkboxes, though it probably won't be perfect depending on the browser.
Different browsers render the actual checkbox (fontwise) differently.

Hope this helps!
--
Christopher A. Reed
"The oxen are slow, but the earth is patient."

"clintonG" <cs*********@REMOVETHISTEXTmetromilwaukee.com> wrote in message
news:ul*************@TK2MSFTNGP12.phx.gbl...
Has anybody figured out how to style this doohickey? I want to move the
label's text properties up so the text lines up with the checkbox itself.

<%= Clinton Gallagher


Dec 21 '05 #5
I was thinking more of using individual CheckBox objects with the Text
property set to String.Empty and then using the Label objects independent of
the CheckBox objects. For example,

<table>
<tr>
<td>
<asp:Label id="lblCBText1" Text="Checkbox #1" runat="server" />
</td>
<td>
<asp:Checkbox id="chkOption1" Text="" Value="1" runat="server" />
</td>
</tr>
.....
</table>

Probably needing to create this from a database, you could use a Repeater
object to build this table for you.

As for the background, again, this goes back to how the browser renders the
checkbox itself. In many cases, several browsers will always use white
within the drawn box regardless of whatever settings you make. If you want
more control over this aspect of the checkbox, you can always create your
own.
--
Christopher A. Reed
"The oxen are slow, but the earth is patient."

"clintonG" <cs*********@REMOVETHISTEXTmetromilwaukee.com> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
Thanks for your comments Christopher but that raises an exception "The
'Text' property of 'asp:ListItem' does not allow child objects."

Apparently the problem is not so much the label and label text that the
ListItem generates but the TD that contains the label text. Ordinarily we
can use paddings and margins to overflow the text container to raise or
lower text a bit here and there as that's all that is ordinarily needed
but not in this case it seems.

I also see the checkbox control is still rendering as a bug which renders
a background color around the checkbox. I've forgotten exactly how to
respond to this IE bug. Do you know what property to modify? Again, as I
recall it was the TD background color properties but I can't remember.

<%= Clinton Gallagher

"Christopher Reed" <ca****@nospam.nospam> wrote in message
news:%2***************@TK2MSFTNGP11.phx.gbl...
Your best bet is to ignore setting the text for your checkboxes and use
label controls instead. Then, if you're using a table for formatting,
you can use valign in the table cells to align your labels with your
checkboxes, though it probably won't be perfect depending on the browser.
Different browsers render the actual checkbox (fontwise) differently.

Hope this helps!
--
Christopher A. Reed
"The oxen are slow, but the earth is patient."

"clintonG" <cs*********@REMOVETHISTEXTmetromilwaukee.com> wrote in
message news:ul*************@TK2MSFTNGP12.phx.gbl...
Has anybody figured out how to style this doohickey? I want to move the
label's text properties up so the text lines up with the checkbox
itself.

<%= Clinton Gallagher



Dec 22 '05 #6

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

Similar topics

4
8056
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...
5
7886
by: Eirik Eldorsen | last post by:
I'm trying to code a reapter that for each listelement show a checkboxlist. I'm almost there. The only thing I can't figure out is how to set the ID of the checkboxlists. This is my code:...
3
2900
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...
5
13372
by: Patrick.O.Ige | last post by:
I'm binding a CheckBoxlist below in the ItemDataBound(the CheckBoxList is in a Datalist) By doing "li.Selected = True" i can see all the checkBoxes are selected. But what i want is to be able...
4
4024
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...
2
5212
by: Patrick.O.Ige | last post by:
I have some boolean value(1 or 0 ) in a table and i want a databinded CheckBoxList to present the selected values on the page.. With CheckBox i know i can se the Checked property like so :-...
2
13652
by: EnjoyLife | last post by:
I am new to ASP.NET and am trying to learn it the best that I can. I am trying to add some code in the If IntRowIndex > -1 statement to mark an item SELECTED before adding it to the CheckBoxList. ...
0
10979
by: jeremy | last post by:
Had a tough time figuring this one out and couldn't find a good solution, so I thought I would post this and hopefully it will help someone out. When using DataBind to dynamically bind a list to...
3
5853
by: onlyprad | last post by:
Hi, I am populating the checkboxlist in (!IsPostBack) block of page load event with some checked items. After populating with checked items I am iterating through the items collection and...
0
7055
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,...
0
6920
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...
0
7059
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,...
0
7010
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...
0
5362
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,...
1
4799
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...
0
4499
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...
0
1311
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 ...
0
203
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...

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.