Bootstrap checkbox-inline and radio-inline with ASP.NET CheckBoxList and RadioButtonList controls

John Avis by | June 20, 2016 | Bootstrap ASP.NET Web Forms

Although you can easily create inline checkboxes and radio buttons using ASP.NET CheckBoxes and RadioButtons using Bootstrap's checkbox-inline and radio-inline classes, it's not so easy with ASP.NET CheckBoxList and RadioButtonList controls.
Although you can easily create inline checkboxes and radio buttons using ASP.NET CheckBoxes and RadioButtons using Bootstrap's checkbox-inline and radio-inline classes, it's not so easy with ASP.NET CheckBoxList and RadioButtonList controls.

There's probably several ways of emulating the Bootstrap inline styling using these ASP.NET controls, this is how I have been doing it.

Additional CSS classes:

.checkboxlist-inline li, .radiobuttonlist-inline li
{
display:inline-block;
}

.checkboxlist-inline, .radiobuttonlist-inline
{
margin-left: 20px;
}

.checkboxlist-inline label, .radiobuttonlist-inline label
{
padding-left:0;
padding-right:30px;
}


Then your ASP.NET controls will need some CSS classes applied, and some special attributes:

<asp:CheckBoxList ID="CheckBoxList1" runat="server" CssClass="list-unstyled checkbox checkboxlist-inline" RepeatDirection="Vertical" RepeatLayout="UnorderedList"></asp:CheckBoxList>

<asp:RadioButtonList ID="RadioButtonList1" runat="server" CssClass="list-unstyled radio radiobuttonlist-inline" RepeatDirection="Vertical" RepeatLayout="UnorderedList"></asp:RadioButtonList>


As you can see, I use the UnorderdedList layout and then change the styling of the LI elements to inline-blocks. By using the Bootstrap checkbox/radio classes combined with the list-unstyled we get a result very similar to the native Bootstrap styling.

Related Posts

Bootstrap Cool Websites

Bootstrap 4 beta Customiser

by John Avis | October 31, 2017

I love Bootstrap v4 and now that it is finally in Beta can start to use it in new projects. But I miss the online customizer that was available for Bootstrap v3.


Bootstrap ASP.NET Web Forms

ASP.NET Web Forms and Bootstrap 3 Modals

by John Avis | July 6, 2017

There are a few methods for hiding and showing Bootstrap 3.x modals in an ASP.NET Web Forms application. This technique is pure ASP.NET (requires no client script) and allows you to show and hide modals by changing the Visible property of a containing PlaceHolder or Panel.


ASP.NET Web Forms

Disable common UpdateProgress controls for an UpdatePanel with an associated UpdateProgress

by John Avis | April 12, 2017

If you have an ASP.NET Web Forms page with multiple UpdatePanels and multiple UpdateProgress controls, sometimes you may want one or more UpdateProgress controls associated with a specific UpdatePanel, and one or more UpdateProgress controls that have no association with an UpdatePanel so are shown when any UpdatePanel is updated.

Comments

There are no comments yet. Be the first to leave a comment!

Leave a Comment
Tags
ASP.NET Html Forms ASP.NET MVC ASP.NET Web Forms ASP.NET Web Pages Bootstrap C# Classic ASP Cool Websites Databases eBay and PayPal Electrical Repairs General Hardware HTML/CSS Jquery/Javascript Media Center Mobile Phones Responsive Web Design SEO and Social Networking Web Design Web Development Web Security web+db Website Hosting Windows XP

About me

...mostly about web development and programming, with a little bit of anything else related to the Internet, computers and technology.

Subscribe

Get the latest posts delivered to your inbox.