Click here to Skip to main content
13,000,127 members (55,786 online)
Rate this:
Please Sign up or sign in to vote.
See more:

i am using checkbox in grid, i am getting the combox from seperate table and join

in the main table.

i need validation operation for that so please anyone

can sent sample.

Thank you,
Posted 2-Jul-12 0:04am
Sandeep Mewara 2-Jul-12 6:23am
1. Your question is not quite clear.
2. Did you try anything by yourself?
chetan virkar 2-Jul-12 6:26am
can u briefly explain your question or paste your code what u write for that?

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Gridview checkbox validation using javascript

Labels: Gridview, Javascript

Hi here I will explain how to check the checked status of checkboxes in gridview using JavaScript


I have a one gridview with checkboxes and one button if user clicks on button I need to raise validation if user doesn’t checked at least one checkbox in gridview for that I have written one JavaScript function to check whether checkboxes selected in gridview or not.

For that write the following code in aspx page

<html xmlns="" >
<head runat="server">
<title>Check all checkboxes if Header checkbox checks</title>
<style type="text/css">
<script type="text/javascript" language="javascript">
function validateCheckBoxes() {
var isValid = false;
var gridView = document.getElementById('<%= gvcheckbox.ClientID %>');
for (var i = 1; i < gridView.rows.length; i++) {
var inputs = gridView.rows[i].getElementsByTagName('input');
if (inputs != null) {
if (inputs[0].type == "checkbox") {
if (inputs[0].checked) {
isValid = true;
return true;
alert("Please select atleast one checkbox");
return false;
<form id="form1" runat="server">

<asp:gridview id="gvcheckbox" cssclass="Gridview" runat="server" autogeneratecolumns="False" xmlns:asp="#unknown">
HeaderStyle-BackColor="#7779AF" HeaderStyle-ForeColor="white">
<asp:checkbox id="chkheader" runat="server" />
<asp:checkbox id="chkchild" runat="server" />

<HeaderStyle HorizontalAlign="Left" />
<itemstyle horizontalalign="Left" />

<asp:boundfield headertext="UserName" datafield="UserName" headerstyle-horizontalalign="Left" />
<asp:boundfield headertext="FirstName" datafield="FirstName" headerstyle-horizontalalign="Left" />
<asp:boundfield headertext="LastName" datafield="LastName" headerstyle-horizontalalign="Left" />

<asp:button runat="server" text="Submit" onclientclick="javascript:validateCheckBoxes()" xmlns:asp="#unknown" />


In code behind bind gridview with some data and check it will work for you


ely_bob 21-Jun-13 0:20am
decent answer, you can do the trick a little more elegantly using
var inputs = $(':input', GRID);
then looping over inputs
and you have an unused variable being set that isn't even needed...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170624.1 | Last Updated 2 Jul 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100