Bootstrap checkbox-inline and radio-inline with ASP.NET CheckBoxList and RadioButtonList controls
by johna | June 20, 2016 | Bootstrap ASP.NET Web Forms Web Development
Update: This applies to Bootstrap 3. See update at end for Bootstrap 4.
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:
Then your ASP.NET controls will need some CSS classes applied, and some special attributes:
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.
Update for Bootstrap 4:
Here are the CSS changes for Bootstrap 4.x.
And here is how your RadioButtonList should be marked up:
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.
Update for Bootstrap 4:
Here are the CSS changes for Bootstrap 4.x.
.checkboxlist-inline li, .radiobuttonlist-inline li
{
display: inline-flex;
align-items: center;
padding-left: 0;
margin-right: .75rem;
position: relative;
}
.checkboxlist-inline li input, .radiobuttonlist-inline li input
{
position: static;
margin-top: 0;
margin-right: .3125rem;
margin-left: 0;
}
.checkboxlist-inline li label, .radiobuttonlist-inline li label {
margin-bottom: 0;
}
And here is how your RadioButtonList should be marked up:
<asp:RadioButtonList ID="RadioButtonList1" runat="server" CssClass="list-unstyled radiobuttonlist-inline" RepeatLayout="UnorderedList"></asp:RadioButtonList>
Related Posts
Converting dBase IV programs to run in the browser
by johna | September 13, 2024
Some pointless entertainment trying to get some old dBase programs running in the browser.
How to set up a debugging using the Turnkey Linux LAMP stack and VS Code
by johna | December 19, 2023
The second part in my guide to setting up a website and database using the Turnkey Linux LAMP stack.
How to set up a website and database using the Turnkey Linux LAMP stack
by johna | November 18, 2023
If you need to host your own website for the purposes of web development, Turnkey Linux LAMP Stack is an easy to install all-in-one solution that you can set up on a spare computer or a VM (Virtual Machine).
Comments
There are no comments yet. Be the first to leave a comment!