In this blog we will know how to insert Checkbox List values into database. Here we use CustomValidator for validating Checkbox List.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Checkboxlist_values_into_database._Default" %>
<!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>Untitled
Page</title>
<script
type="text/javascript">
function selectone(chk)
{
var chkList =
chk.parentNode.parentNode.parentNode;
var chks = chkList.getElementsByTagName("input");
for(var
i=0;i<chks.length;i++)
{
if(chks[i] != chk && chk.checked)
{
chks[i].checked=false;
}
}
}
function Validate(source, args)
{
var
chkList= document.getElementById ('<%=
nationality_chk.ClientID %>');
var
chkListinputs = chkList.getElementsByTagName("input");
for(var
i=0;i<chkListinputs .length;i++)
{
if(chkListinputs
[i].checked)
{
args.IsValid = true;
return;
}
}
args.IsValid = false;
}
</script>
</head>
<body>
<form
id="form1"
runat="server">
<div>
<table
align="center">
<tr>
<td
colspan="2">
<h3>
Registraion</h3>
</td>
</tr>
<tr>
<td>
Name:</td>
<td>
<asp:TextBox
ID="txtName"
runat="server"></asp:TextBox>
</td>
<td><asp:RequiredFieldValidator
ID="RequiredFieldValidator2"
runat="server"
ErrorMessage="Enter
Name" ControlToValidate="txtName"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
Email</td>
<td>
<asp:TextBox
ID="txtEmail"
runat="server"></asp:TextBox>
</td>
<td><asp:RequiredFieldValidator
ID="RequiredFieldValidator3"
runat="server"
ErrorMessage="Enter
Email" ControlToValidate="txtEmail"></asp:RequiredFieldValidator>
</td>
<td>
<asp:RegularExpressionValidator
ID="RegularExpressionValidator1"
runat="server"
ErrorMessage="Invaid
Email" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
ControlToValidate="txtEmail"></asp:RegularExpressionValidator>
</td>

Join the conversation! Your thoughts help the community grow.