Dave Burke : Freelance .NET Web Developer specializing in Online Communities

Simple tip on controlling display of asp:CheckBoxList control

I needed to generate a two-column checklistbox in a limited area and I just couldn't live with the wrapped formatting of the text around the individual checkboxes.  The top image shows what the original looked like.  The bottom image shows the result I was shooting for. 

I considered creating a class inherited from the ListControl object and override...the OnPreRender method?  I don't know.  That seems to have been the most elegant solution.  But time being money and this being a work assignment--not a late-night coding exploratory session--I came up with a far simpler solution.

int i = 0;
foreach (DataRowView drv in ds.Tables["subs"].DefaultView)
{
 cblServices.Items[i].Selected = bool.Parse(drv["active"].ToString());
 
cblServices.Items[i].Text = "<td valign=\"bottom\">" + cblServices.Items[i].Text + "</td>";
 i++;
}

The tip is in bold.  Put the text in a table cell.  While the resulting code is 100% HTML standard, it renders perfectly in both IE and Firefox.  So I'm happy..and done with this checkboxlist. 

Another timesaver for you if you use this approach is setting the CssClass style correctly on the checkboxlist.  That looks like so:

.smchkbox TD
{
 COLOR: black;
 border-style: none;
 background-color: white;
 font-family: Arial;
 font-size: 11px;
 vertical-align: baseline
}


Comments (0) | Post RSS RSS comment feed

Posted on 11/5/2004 12:08:00 PM by Dave Burke
Categories: .NET
Tags:

Related posts


Powered by BlogEngine.NET 2.0.0.36
Theme by Dave Burke