Skip to content

Instantly share code, notes, and snippets.

@rionmonster
Created April 27, 2016 14:19
Show Gist options
  • Save rionmonster/42aaf6e13827cb36d1c99b8ac182f881 to your computer and use it in GitHub Desktop.
Save rionmonster/42aaf6e13827cb36d1c99b8ac182f881 to your computer and use it in GitHub Desktop.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CheckBoxChecking.aspx.cs" Inherits="Example.CheckBoxChecking" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:CheckBox ID="CheckBox1" runat="server" />
<asp:CheckBox ID="CheckBox2" runat="server" />
<asp:CheckBox ID="CheckBox3" runat="server" />
<asp:CheckBox ID="CheckBox4" runat="server" />
<asp:CheckBox ID="CheckBox5" runat="server" />
<asp:Button ID="GetCheckedCount" runat="server" OnClick="GetCheckedCount_Click" Text="Get CheckBox Count" />
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Example
{
public partial class CheckBoxChecking : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void GetCheckedCount_Click(object sender, EventArgs e)
{
var checkedBoxes = Form.Controls.OfType<CheckBox>().Count(c => c.Checked);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment