Checkbox list Example using javascript
CheckBoxList control example:
CheckBoxList is a Standard Server control of
asp.net. In this post we consider a
simple example of CheckBoxList control. in this tutorial we also consider Example of Check Uncheck all html CheckBox controls using jQuery:
As we know that this control gives to permission to use to
select more than one option at some time.
Code on aspx page
<%@ Page
Language="C#"
AutoEventWireup="true"
CodeFile="checkboxlist.aspx.cs"
Inherits="checkboxlist"
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD
XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script runat="server">
protected void
Button1_Click(object sender, System.EventArgs e) {
Label1.Text = "You are selected :<br
/>";
foreach(ListItem
li1 in CheckBoxList1.Items){
if (li1.Selected == true)
{
Label1.Text += li1.Text + "<br
/>";
}
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server"></asp:Label>
<br />
<asp:Label ID="Label2" runat="server"
Text="Select favorites" AssociatedControlID="CheckBoxList1"></asp:Label>
<asp:CheckBoxList ID="CheckBoxList1"
runat="server">
<asp:ListItem>Oppption1</asp:ListItem>
<asp:ListItem>Oppption2</asp:ListItem>
<asp:ListItem>Oppption3</asp:ListItem>
<asp:ListItem>Oppption4</asp:ListItem>
<asp:ListItem>Oppption5</asp:ListItem>
</asp:CheckBoxList>
<br />
<asp:Button ID="Button1"
runat="server"
Text="Show
Result" OnClick="Button1_Click" />
</div>
</form>
</body>
</html>
How to use CheckBox control in asp.net with JavaScript:
In this checklist Example take one check list with id “CheckBoxList1”
and consider five items. And on javascript function for display how many and whose
are selected in particular list.
Check List |