How to change CheckBoxList text align in asp.net c#

CheckBoxList TextAlign
The following asp.net c# example code demonstrate us how can we set or change CheckBoxList control's text alignment programmatically at run time. CheckBoxList is a multi-selection check box group. CheckBoxList control render a virtual group of individual CheckBox controls. So, we can manage all ChekBoxes within a CheckBoxList very easily.

CheckBoxList TextALign property allow us to set or change text alignment for the check boxes within the group (CheckBoxList). We can assign any value from the System.Web.UI.WebControls.TextAlign enumeration as CheckBoxList TextAlign property value. TextAlign enumeration have two possible values, Left and Right. So, we can set CheckBoxList check boxes text alignment left or right. CheckBoxList TextAlign Left means Text associated with a check box appear to the left of the check box control.

CheckBoxList control through ArgumentOutOfRangeException, if we set a TextAlign property value which is not a value from TextAlign enumeration.
CheckBoxListTextAlign.aspx

<%@ Page Language="C#" %>

<!DOCTYPE html>

<script runat="server">
    protected void Button1_Click(object sender, System.EventArgs e)
    {
        CheckBoxList1.TextAlign = TextAlign.Left;
    }
    protected void Button2_Click(object sender, System.EventArgs e)
    {
        CheckBoxList1.TextAlign = TextAlign.Right;
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>How to use TextAlign (text align left right) in CheckBoxList</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h2 style="color:Green">CheckBoxList: Change TextAlign</h2>
        <asp:Label 
             ID="Label1"
             runat="server"
             Font-Bold="true"
             ForeColor="SaddleBrown"
             Text="asp.net controls"
             >
        </asp:Label>
        <asp:CheckBoxList 
             ID="CheckBoxList1"
             runat="server"
             BackColor="Lavender"
             ForeColor="Magenta"
             Font-Bold="true"
             >
             <asp:ListItem>MultiView</asp:ListItem>
             <asp:ListItem>Substitution</asp:ListItem>
             <asp:ListItem>AppearanceEditorPart</asp:ListItem>
             <asp:ListItem>BehaviorEditorPart</asp:ListItem>
             <asp:ListItem>UpdateProgress</asp:ListItem>
        </asp:CheckBoxList>
        <br />
        <asp:Button 
             ID="Button1"
             runat="server"
             Font-Bold="true"
             ForeColor="SaddleBrown"
             Text="TextAlign Left"
             OnClick="Button1_Click"
             />
        <asp:Button 
             ID="Button2"
             runat="server"
             Font-Bold="true"
             ForeColor="SaddleBrown"
             Text="TextAlign Right"
             OnClick="Button2_Click"
             />
    </div>
    </form>
</body>
</html>
More asp.net examples