How to use AutoPostBack in asp.net c# CheckBoxList

AutoPostBack feature in CheckBoxList
CheckBoxList is an asp.net web server control. this server control creates a multi-selection check box group. checkboxlist can be dynamically populated by binding the data source.

CheckBoxList AutoPostBack property get or set a value indicating whether a postback to the server automatically occurs when the user changes the checkboxlist selection. this property value type is System.Boolean. if we set the property value to 'true' then a postback automatically occurs when the user changes the checkboxlist selection. and if we set this property value to 'false' then automatic postback to server will be disable. the default value of this property is false.

CheckBoxList SelectedIndexChanged event occurs when the selection of checkboxlist changes between post to the server. to work this event properly we need to set the checkboxlist AutoPostBack property value to true.

the following asp.net c# example code demonstrate us how can we use AutoPostBack property of checkboxlist in an asp.net application.
CheckBoxListAutoPostBack.aspx

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

<!DOCTYPE html>

<script runat="server">
    protected void CheckBoxList1_SelectedIndexChnaged(object sender, System.EventArgs e)
    {
        Label1.Text = "You Selected:<br /><i>";
        foreach (ListItem li in CheckBoxList1.Items)
        {
            if (li.Selected == true)
            {
                Label1.Text += li.Text + "<br />";
            }
        }
        Label1.Text += "</i>";
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>How to use AutoPostBack feature in CheckBoxList</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h2 style="color:Maroon">CheckBoxList: AutoPostBack</h2>
        <asp:Label 
             ID="Label1"
             runat="server"
             Font-Bold="true"
             ForeColor="SeaGreen"
             Font-Size="Large"
             >
        </asp:Label>
        <br />
        <asp:Label 
             ID="Label2"
             runat="server"
             Font-Bold="true"
             ForeColor="DarkBlue"
             Text="asp.net controls"
             >
        </asp:Label>
        <asp:CheckBoxList 
             ID="CheckBoxList1"
             runat="server"
             AutoPostBack="true"
             OnSelectedIndexChanged="CheckBoxList1_SelectedIndexChnaged"
             >
             <asp:ListItem>Image</asp:ListItem>
             <asp:ListItem>TreeView</asp:ListItem>
             <asp:ListItem>Literal</asp:ListItem>
             <asp:ListItem>ValidationSummary</asp:ListItem>
             <asp:ListItem>MultiView</asp:ListItem>
        </asp:CheckBoxList>
    </div>
    </form>
</body>
</html>
More asp.net examples