How to use CheckBoxList OnDataBound event in ASP.Net C#

In this ASP.Net Tutorials we will learn How to use CheckBoxList OnDataBound event in ASP.Net C#.

STEP 1 – Design the ASP.Net Web form with one CheckBoxList control, one Button control and one Label Control:

 <table style=”width: 464px”>
<tr>
<td colspan=”1″ style=”width: 257px; height: 24px”>
<strong><span style=”font-size: 14pt; color: #6600cc; font-family: Arial”>OnDataBinding
Event in CheckBoxList</span></strong></td>
</tr>
<tr>
<td style=”width: 257px; height: 24px; text-align: center;”>
&nbsp;
<asp:Button ID=”Button1″ runat=”server” OnClick=”Button1_Click” Text=”View CheckBoxList” Font-Bold=”True” Font-Size=”Medium” /></td>
</tr>
<tr>
<td style=”width: 257px; height: 22px; text-align: center;”>
<asp:Label ID=”Label1″ runat=”server”></asp:Label><asp:CheckBoxList ID=”CheckBoxList1″ runat=”server” OnDataBinding=”CheckBoxList1_DataBinding”
OnDataBound=”CheckBoxList1_DataBound” Width=”168px”>
</asp:CheckBoxList></td>
</tr>
<tr>
<td style=”width: 257px; height: 22px; text-align: center”>
</td>
</tr>
</table>

The ASP.Net CheckboxList Control OnDataBound Event Example output is :

ASP.Net CheckboxList Control OnDataBound Event Example with C#

ASP.Net CheckboxList Control OnDataBound Event Example with C#

STEP 2 – write below code on Button Click Event and OnDataBound Event of ASP.Net code page:

protected void Button1_Click(object sender, EventArgs e)
{
string[] Days = { “Sunday”, “Monday”, “Tusday”, “Wednesday”, “Thursday” };
CheckBoxList1.DataSource = Days;
CheckBoxList1.DataBind();
}
protected void CheckBoxList1_DataBound(object sender, EventArgs e)
{
Label1.Text = “Week Days”;
Label1.ForeColor = System.Drawing.Color.DarkBlue;
Label1.Font.Size = FontUnit.Medium;
CheckBoxList1.Items[1].Selected = true;
CheckBoxList1.Items[2].Selected = true;
CheckBoxList1.Items[4].Enabled = false;
}

The ASP.Net CheckboxList Control OnDataBound Event Example output is :

ASP.Net CheckboxList Control OnDataBound Event Example with C#

ASP.Net CheckboxList Control OnDataBound Event Example with C#

I hope this ASP.Net tutorials of Checkboxlist control OnDataBound Event will help you….

Leave a Reply

Your email address will not be published. Required fields are marked *

5 + 5 =


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">