Hi Friends,
I have a gridview. and I am having checkboxes in all the columns and all the rows. Like it is about selecting subjects.
My Problem is when I select a Checkbox in First column of any row, all the checkboxes in that particular row should also be selected.
How can I do this... . I have done all checkboxes checked for column, but no idea about row.
Please guide.
Thanks.
![]() |
0 |
![]() |
Hi,
this can be done with the help of jQuery, a great & free javascript library. Take a look at this article: Check All Checkboxes in GridView using JQuery.
Grz, Kris.
Read my blog. Handy Firefox plugins for web developers.
Workaround for non working Mark as answer buttons.
![]() |
0 |
![]() |
try this sample
<head> <script type ="text/javascript"> function CheckAll(obj) { var row = obj.parentNode.parentNode; var inputs = row.getElementsByTagName("input") ; for(var i=0;i<inputs.length;i++) { if(inputs[i].type=="checkbox") { inputs[i].checked=obj.checked; } } } head> <body> <asp:GridView ID="GridView2" runat="server"> <Columns> <asp:TemplateField> <ItemTemplate> <asp:CheckBox ID="CheckBox1" runat="server" onclick ="CheckAll(this)" /> </ItemTemplate> </asp:TemplateField> <asp:TemplateField> <ItemTemplate> <asp:CheckBox ID="CheckBox2" runat="server" /> </ItemTemplate> </asp:TemplateField> <asp:TemplateField> <ItemTemplate> <asp:CheckBox ID="CheckBox3" runat="server" /> </ItemTemplate> </asp:TemplateField> <asp:BoundField DataField ="CustomerID" /> </Columns> </asp:GridView> </body>
MAK | Mark as Answer if this reply helps you | |
![]() MVP ASP/ASP.Net | ASP.Net Hosting : Host Depot | My Site : ASPSnippets |
![]() |
0 |
![]() |
This is not working , my grid looks like this
<head id="Head1" runat="server">
<script type="text/javascript">
function CheckAll(obj)
{
var row = obj.parentNode.parentNode;
var inputs = row.getElementsByTagName("input") ;
for(var i=0;i<inputs.length;i++)
{
if(inputs[i].type=="checkbox")
{
inputs[i].checked=obj.checked;}
}
}</script>
</head>
<asp:GridView ID="grdManage" runat="server" AutoGenerateColumns="False" >
<Columns>
<asp:TemplateField >
<ItemTemplate >
<table class="style1">
<tr>
<td>
<asp:Label ID="lblholidayname" runat="server" Height="16px"
Text='<%# Bind("Description") %>' Tooltip='<%# Bind("Holiday") %>'
Width="100px"></asp:Label>
</td>
<td align="right" class="style2">
<asp:CheckBox ID="chkAll" runat="server" Text="Select All" TextAlign="Left"
Width="80px" onclick ="CheckAll(this)" />
</td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate>
<asp:Label ID="lblstateID1" runat="server" Tooltip='<%# Bind("1") %>'></asp:Label>
<asp:CheckBox ID="chk1" runat="server" />
</ItemTemplate>
<ItemStyle CssClass="atext" HorizontalAlign="Center" Wrap="True" />
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate>
<asp:Label ID="lblstateID2" runat="server" Tooltip='<%# Bind("2") %>'></asp:Label>
<asp:CheckBox ID="chk2" runat="server" />
</ItemTemplate>
<ItemStyle CssClass="atext" HorizontalAlign="Center" Wrap="True" />
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate>
<asp:Label ID="lblstateID3" runat="server" Tooltip='<%# Bind("3") %>'></asp:Label>
<asp:CheckBox ID="chk3" runat="server" />
</ItemTemplate>
<ItemStyle CssClass="atext" HorizontalAlign="Center" Wrap="True" />
</asp:TemplateField>
</Columns>
</asp:GridView>
![]() |
0 |
![]() |
kindly read the question carefully, ur code is not relevent to my question
![]() |
0 |
![]() |
Hi,
Check out these links
Thanks,
Farooq
Mark as answer if this post helpfull to you.
Don't be afraid to be wrong; otherwise you'll never be right.
![]() |
0 |
![]() |
hi Farooq
Read my question again carefully .
![]() |
0 |
![]() |
Hi,
I think you're after this:
Update: just changed the code to also unselect the checkboxes!!!
<!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> <title></title> <style type="text/css"> .style1 { width: 100%; } </style> </head> <body> <table class="style1" id="myTable"> <tr> <td> <input type="checkbox" /></td> <td> <input type="checkbox" /></td> <td> <input type="checkbox" /></td> </tr> <tr> <td> <input type="checkbox" /></td> <td> <input type="checkbox" /></td> <td> <input type="checkbox" /></td> </tr> <tr> <td> <input type="checkbox" /></td> <td> <input type="checkbox" /></td> <td> <input type="checkbox" /></td> </tr> <tr> <td> <input type="checkbox" /></td> <td> <input type="checkbox" /></td> <td> <input type="checkbox" /></td> </tr> <tr> <td> <input type="checkbox" /></td> <td> <input type="checkbox" /></td> <td> <input type="checkbox" /></td> </tr> </table> <script src="../../jQuery/jquery-1.3.2-vsdoc2.js" type="text/javascript"></script> <script type="text/javascript"> $(document).ready(function() { $('#myTable td:nth-child(1) :checkbox').click(function() { var c = $(this).attr('checked'); $(this).parents('tr').find('td:gt(0) :checkbox').attr('checked', c); }); }); </script> </body> </html>
This little bit of jquery will first find the checkbox in the first column, then find all the checkboxes in the same row and set the checked attribute to checked.
Grz, Kris.
Read my blog. Handy Firefox plugins for web developers.
Workaround for non working Mark as answer buttons.
![]() |
0 |
![]() |
This approach is using jQuery as requested, but it doesn't look very nice. I recommend use javascript.
1. aspx file
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="multicheckbox.aspx.cs" Inherits="GridViewTest.multicheckbox" %>
<!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 src="scripts/jquery-1.3.2.js" type="text/javascript" language="javascript"></script>
<script type="text/javascript" language="javascript">
window.onload = function() { bindevent(); };
function bindevent() {
$("input[id$=Checkbox1]").bind("click", function(event) { checkboxHandler(event); });
}
function checkboxHandler(e) {
var name = "#"+e.target.id.toString();
var b = $(name)[0].checked;
$(name).parent().siblings().children("input:checkbox").attr("checked", b);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<input id="Checkbox1" type="checkbox" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<input id="Checkbox2" type="checkbox" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<input id="Checkbox3" type="checkbox" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>2. code behind file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace GridViewTest
{
public partial class multicheckbox : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
List<int> lst = new List<int>();
lst.Add(1);
GridView1.DataSource = lst;
GridView1.DataBind();
}
}
}
![]() |
0 |
![]() |
Sorry, please amend my previous solution: add attributes runat="server" to all checkbox to make it possible to generate unique client id.
Thanks
![]() |
0 |
![]() |
hi,
where can i find the script file with u have used ?
src="scripts/jquery-1.3.2.js"
![]() |
0 |
![]() |
1. jQuery can be downloaded here :
http://docs.jquery.com/Downloading_jQuery
2. create scripts folder and put jQuery lib file and vsdoc(optional) file in there.
![]() |
0 |
![]() |
dear yasserzaid
this will check all the checkbox in the form , i want only the perticuler row checkbox is to be checked, please read the question and dont kill ur time in sending unwanted answers. dont send copy pasted answers without understanding the question
![]() |
0 |
![]() |
hi,
i have downloaded the script file but still the code is not working and the problem is not resolved , kindly suggest
![]() |
0 |
![]() |
Hi,
lalitsinghnegiaspnet:
src="scripts/jquery-1.3.2.js"You can download it from here: http://docs.jquery.com/Downloading_jQuery#Current_Release.
Grz, Kris.
Read my blog. Handy Firefox plugins for web developers.
Workaround for non working Mark as answer buttons.
![]() |
0 |
![]() |
Hi,
lalitsinghnegiaspnet:
i have downloaded the script file but still the code is not working and the problem is not resolved , kindly suggestCan you upload your altered code that makes use of the scripts so we can better investigate it?
Grz, Kris.
Read my blog. Handy Firefox plugins for web developers.
Workaround for non working Mark as answer buttons.
![]() |
0 |
![]() |
it sounds strange. jquery-1.3.2.js is used just like normal js file. All u need to do is referencing it.
what is the error then?
![]() |
0 |
![]() |
I dont think that u need to use javascript.
Well in following code i assume that u have a datakey name when went to serbver side..(to recognize the row.)
On ther srver side..that is in ur aspx.cs
here gvDynamicGrid is your grid.
protected void gvDynamicGrid_OnRowDataBound(object sender, GridViewRowEventArgs e)
{if (e.Row.RowType == DataControlRowType.DataRow)
{
int rowID = int.Parse(e.Keys[0].ToString());
if(rowID == "2") //to check for the row id..not neccessariy in ur case.
{CheckBox chk1= (CheckBox )e.Row.FindControl("chk1");
CheckBox chk2= (CheckBox )e.Row.FindControl("chk2");
chk1.Checked = true;
chk2.Checked = true;
.......
}
}
}
Please mark as answer if it helped u!
![]() |
0 |
![]() |
it sounds strange. jquery-1.3.2.js is just js lib file it needs to be reference by aspx file or your own js file.
what is the error then? Is it something to do with js reference?
![]() |
0 |
![]() |
kavita_khandhadia ,
i want to check the checkbox at runtime , dynamically , when i check the first column's check box ( in my code it is selectall), i think ur code will do it when RowDataBound event is called .but not on the event of the checkbox ( click event of the checkbox).
kindly suggest
![]() |
0 |
![]() |
Hi,
XIII Grz, Kris.:
Can you upload your altered code that makes use of the scripts so we can better investigate it?
Grz, Kris.
here is my code
<script src="jquery-1.3.2.js" type="text/javascript" language="javascript"></script>
<script type="text/javascript" language="javascript">
window.onload = function() { bindevent(); };
function bindevent() {
$("input[id$=chkAll]").bind("click", function(event) { checkboxHandler(event); });
}
function checkboxHandler(e) {
var name = "#"+e.target.id.toString();
var b = $(name)[0].checked;
$(name).parent().siblings().children("input:checkbox").attr("checked", b);
}
</script>
<asp:GridView ID="grdManage" runat="server" AutoGenerateColumns="False" >
<Columns>
<asp:TemplateField >
<ItemTemplate >
<table class="style1">
<tr>
<td>
<asp:Label ID="lblholidayname" runat="server" Height="16px"
Text='<%# Bind("Description") %>' Tooltip='<%# Bind("Holiday") %>'
Width="100px"></asp:Label>
</td>
<td align="right" class="style2">
<asp:CheckBox ID="chkAll" runat="server" Text="Select All" TextAlign="Left"
Width="80px" />
</td>
</tr>
</table>
</ItemTemplate>
<ItemStyle Wrap ="true" Width="120px" HorizontalAlign="Left" VerticalAlign="Middle" Font-Size="Smaller" />
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate>
<asp:Label ID="lblstateID1" runat="server" Tooltip='<%# Bind("1") %>'></asp:Label>
<asp:CheckBox ID="chk1" runat="server" />
</ItemTemplate>
<ItemStyle CssClass="atext" HorizontalAlign="Center" Wrap="True" />
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate>
<asp:Label ID="lblstateID2" runat="server" Tooltip='<%# Bind("2") %>'></asp:Label>
<asp:CheckBox ID="chk2" runat="server" />
</ItemTemplate>
<ItemStyle CssClass="atext" HorizontalAlign="Center" Wrap="True" />
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate>
<asp:Label ID="lblstateID3" runat="server" Tooltip='<%# Bind("3") %>'></asp:Label>
<asp:CheckBox ID="chk3" runat="server" />
</ItemTemplate>
<ItemStyle CssClass="atext" HorizontalAlign="Center" Wrap="True" />
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate>
<asp:Label ID="lblstateID4" runat="server" Tooltip='<%# Bind("4") %>'></asp:Label>
<asp:CheckBox ID="chk4" runat="server" />
</ItemTemplate>
<ItemStyle CssClass="atext" HorizontalAlign="Center" Wrap="True" />
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate>
<asp:Label ID="lblstateID5" runat="server" Tooltip='<%# Bind("5") %>'></asp:Label>
<asp:CheckBox ID="chk5" runat="server" />
</ItemTemplate>
<ItemStyle CssClass="atext" HorizontalAlign="Center" Wrap="True" />
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate>
<asp:Label ID="lblstateID6" runat="server" Tooltip='<%# Bind("6") %>'></asp:Label>
<asp:CheckBox ID="chk6" runat="server" />
</ItemTemplate>
<ItemStyle CssClass="atext" HorizontalAlign="Center" Wrap="True" />
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate>
<asp:Label ID="lblstateID7" runat="server" Tooltip='<%# Bind("7") %>'></asp:Label>
<asp:CheckBox ID="chk7" runat="server" />
</ItemTemplate>
<ItemStyle CssClass="atext" HorizontalAlign="Center" Wrap="True" />
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate>
<asp:Label ID="lblstateID8" runat="server" Tooltip='<%# Bind("8") %>'></asp:Label>
<asp:CheckBox ID="chk8" runat="server" />
</ItemTemplate>
<ItemStyle CssClass="atext" HorizontalAlign="Center" Wrap="True" />
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate>
<asp:Label ID="lblstateID9" runat="server" Tooltip='<%# Bind("9") %>'></asp:Label>
<asp:CheckBox ID="chk9" runat="server" />
</ItemTemplate>
<ItemStyle CssClass="atext" HorizontalAlign="Center" Wrap="True" />
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate>
<asp:Label ID="lblstateID10" runat="server" Tooltip='<%# Bind("10") %>'></asp:Label>
<asp:CheckBox ID="chk10" runat="server" />
</ItemTemplate>
<ItemStyle CssClass="atext" HorizontalAlign="Center" Wrap="True" />
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate>
<asp:Label ID="lblstateID11" runat="server" Tooltip='<%# Bind("11") %>'></asp:Label>
<asp:CheckBox ID="chk11" runat="server" />
</ItemTemplate>
<ItemStyle CssClass="atext" HorizontalAlign="Center" Wrap="True" />
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate>
<asp:Label ID="lblstateID12" runat="server" Tooltip='<%# Bind("12") %>'></asp:Label>
<asp:CheckBox ID="chk12" runat="server" />
</ItemTemplate>
<ItemStyle CssClass="atext" HorizontalAlign="Center" Wrap="True" />
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate>
<asp:Label ID="lblstateID13" runat="server" Tooltip='<%# Bind("13") %>'></asp:Label>
<asp:CheckBox ID="chk13" runat="server" />
</ItemTemplate>
<ItemStyle CssClass="atext" HorizontalAlign="Center" Wrap="True" />
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate>
<asp:Label ID="lblstateID14" runat="server" Tooltip='<%# Bind("14") %>'></asp:Label>
<asp:CheckBox ID="chk14" runat="server" />
</ItemTemplate>
<ItemStyle CssClass="atext" HorizontalAlign="Center" Wrap="True" />
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate>
<asp:Label ID="lblstateID15" runat="server" Tooltip='<%# Bind("15") %>'></asp:Label>
<asp:CheckBox ID="chk15" runat="server" />
</ItemTemplate>
<ItemStyle CssClass="atext" HorizontalAlign="Center" Wrap="True" />
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate>
<asp:Label ID="lblstateID16" runat="server" Tooltip='<%# Bind("16") %>'></asp:Label>
<asp:CheckBox ID="chk16" runat="server" />
</ItemTemplate>
<ItemStyle CssClass="atext" HorizontalAlign="Center" Wrap="True" />
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate>
<asp:Label ID="lblstateID17" runat="server" Tooltip='<%# Bind("17") %>'></asp:Label>
<asp:CheckBox ID="chk17" runat="server" />
</ItemTemplate>
<ItemStyle CssClass="atext" HorizontalAlign="Center" Wrap="True" />
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate>
<asp:Label ID="lblstateID18" runat="server" Tooltip='<%# Bind("18") %>'></asp:Label>
<asp:CheckBox ID="chk18" runat="server" />
</ItemTemplate>
<ItemStyle CssClass="atext" HorizontalAlign="Center" Wrap="True" />
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate>
<asp:Label ID="lblstateID19" runat="server" Tooltip='<%# Bind("19") %>'></asp:Label>
<asp:CheckBox ID="chk19" runat="server" />
</ItemTemplate>
<ItemStyle CssClass="atext" HorizontalAlign="Center" Wrap="True" />
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate>
<asp:Label ID="lblstateID20" runat="server" Tooltip='<%# Bind("20") %>'></asp:Label>
<asp:CheckBox ID="chk20" runat="server" />
</ItemTemplate>
<ItemStyle CssClass="atext" HorizontalAlign="Center" Wrap="True" />
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate>
<asp:Label ID="lblstateID21" runat="server" Tooltip='<%# Bind("21") %>'></asp:Label>
<asp:CheckBox ID="chk21" runat="server" />
</ItemTemplate>
<ItemStyle CssClass="atext" HorizontalAlign="Center" Wrap="True" />
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate>
<asp:Label ID="lblstateID22" runat="server" Tooltip='<%# Bind("22") %>'></asp:Label>
<asp:CheckBox ID="chk22" runat="server" />
</ItemTemplate>
<ItemStyle CssClass="atext" HorizontalAlign="Center" Wrap="True" />
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate>
<asp:Label ID="lblstateID23" runat="server" Tooltip='<%# Bind("23") %>'></asp:Label>
<asp:CheckBox ID="chk23" runat="server" />
</ItemTemplate>
<ItemStyle CssClass="atext" HorizontalAlign="Center" Wrap="True" />
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate>
<asp:Label ID="lblstateID24" runat="server" Tooltip='<%# Bind("24") %>'></asp:Label>
<asp:CheckBox ID="chk24" runat="server" />
</ItemTemplate>
<ItemStyle CssClass="atext" HorizontalAlign="Center" Wrap="True" />
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate>
<asp:Label ID="lblstateID25" runat="server" Tooltip='<%# Bind("25") %>'></asp:Label>
<asp:CheckBox ID="chk25" runat="server" />
</ItemTemplate>
<ItemStyle CssClass="atext" HorizontalAlign="Center" Wrap="True" />
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate>
<asp:Label ID="lblstateID26" runat="server" Tooltip='<%# Bind("26") %>'></asp:Label>
<asp:CheckBox ID="chk26" runat="server" />
</ItemTemplate>
<ItemStyle CssClass="atext" HorizontalAlign="Center" Wrap="True" />
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate>
<asp:Label ID="lblstateID27" runat="server" Tooltip='<%# Bind("27") %>'></asp:Label>
<asp:CheckBox ID="chk27" runat="server" />
</ItemTemplate>
<ItemStyle CssClass="atext" HorizontalAlign="Center" Wrap="True" />
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate>
<asp:Label ID="lblstateID28" runat="server" Tooltip='<%# Bind("28") %>'></asp:Label>
<asp:CheckBox ID="chk28" runat="server" />
</ItemTemplate>
<ItemStyle CssClass="atext" HorizontalAlign="Center" Wrap="True" />
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate>
<asp:Label ID="lblstateID29" runat="server" Tooltip='<%# Bind("29") %>'></asp:Label>
<asp:CheckBox ID="chk29" runat="server" />
</ItemTemplate>
<ItemStyle CssClass="atext" HorizontalAlign="Center" Wrap="True" />
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate>
<asp:Label ID="lblstateID30" runat="server" Tooltip='<%# Bind("30") %>'></asp:Label>
<asp:CheckBox ID="chk30" runat="server" />
</ItemTemplate>
<ItemStyle CssClass="atext" HorizontalAlign="Center" Wrap="True" />
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate>
<asp:Label ID="lblstateID31" runat="server" Tooltip='<%# Bind("31") %>'></asp:Label>
<asp:CheckBox ID="chk31" runat="server" />
</ItemTemplate>
<ItemStyle CssClass="atext" HorizontalAlign="Center" Wrap="True" />
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate>
<asp:Label ID="lblstateID32" runat="server" Tooltip='<%# Bind("32") %>'></asp:Label>
<asp:CheckBox ID="chk32" runat="server" />
</ItemTemplate>
<ItemStyle CssClass="atext" HorizontalAlign="Center" Wrap="True" />
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate>
<asp:Label ID="lblstateID33" runat="server" Tooltip='<%# Bind("33") %>'></asp:Label>
<asp:CheckBox ID="chk33" runat="server" />
</ItemTemplate>
<ItemStyle CssClass="atext" HorizontalAlign="Center" Wrap="True" />
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate>
<asp:Label ID="lblstateID34" runat="server" Tooltip='<%# Bind("34") %>'></asp:Label>
<asp:CheckBox ID="chk34" runat="server" />
</ItemTemplate>
<ItemStyle CssClass="atext" HorizontalAlign="Center" Wrap="True" />
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate>
<asp:Label ID="lblstateID35" runat="server" Tooltip='<%# Bind("35") %>'></asp:Label>
<asp:CheckBox ID="chk35" runat="server" />
</ItemTemplate>
<ItemStyle CssClass="atext" HorizontalAlign="Center" Wrap="True" />
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate>
<asp:Label ID="lblstateID36" runat="server" Tooltip='<%# Bind("36") %>'></asp:Label>
<asp:CheckBox ID="chk36" runat="server" />
</ItemTemplate>
<ItemStyle CssClass="atext" HorizontalAlign="Center" Wrap="True" />
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate>
<asp:Label ID="lblstateID37" runat="server" Tooltip='<%# Bind("37") %>'></asp:Label>
<asp:CheckBox ID="chk37" runat="server" />
</ItemTemplate>
<ItemStyle CssClass="atext" HorizontalAlign="Center" Wrap="True" />
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate>
<asp:Label ID="lblstateID38" runat="server" Tooltip='<%# Bind("38") %>'></asp:Label>
<asp:CheckBox ID="chk38" runat="server" />
</ItemTemplate>
<ItemStyle CssClass="atext" HorizontalAlign="Center" Wrap="True" />
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate>
<asp:Label ID="lblstateID39" runat="server" Tooltip='<%# Bind("39") %>'></asp:Label>
<asp:CheckBox ID="chk39" runat="server" />
</ItemTemplate>
<ItemStyle CssClass="atext" HorizontalAlign="Center" Wrap="True" />
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate>
<asp:Label ID="lblstateID40" runat="server" Tooltip='<%# Bind("40") %>'></asp:Label>
<asp:CheckBox ID="chk40" runat="server" />
</ItemTemplate>
<ItemStyle CssClass="atext" HorizontalAlign="Center" Wrap="True" />
</asp:TemplateField>
</Columns>
</asp:GridView>
![]() |
0 |
![]() |
lalitsinghnegiaspnet:
kindly read the question carefully, ur code is not relevent to my question
Unless you paste your Grid How can I predict what you want
Here is the code that works for your Grid
<head> <script type ="text/javascript"> function CheckAll(obj) { var row = obj.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode; var inputs = row.getElementsByTagName("input") ; for(var i=0;i<inputs.length;i++) { if(inputs[i].type=="checkbox") { inputs[i].checked=obj.checked; } } } head> <body> <asp:GridView ID="grdManage" runat="server" AutoGenerateColumns="False" > <Columns> <asp:TemplateField > <ItemTemplate > <table class="style1"> <tr> <td> <asp:Label ID="lblholidayname" runat="server" Height="16px" Text='<%# Bind("Description") %>' Tooltip='<%# Bind("Holiday") %>' Width="100px"></asp:Label> </td> <td align="right" class="style2"> <asp:CheckBox ID="chkAll" runat="server" Text="Select All" TextAlign="Left" Width="80px" onclick ="CheckAll(this)" /> </td> </tr> </table> </ItemTemplate> </asp:TemplateField> <asp:TemplateField > <ItemTemplate> <asp:Label ID="lblstateID1" runat="server" Tooltip='<%# Bind("1") %>'></asp:Label> <asp:CheckBox ID="chk1" runat="server" /> </ItemTemplate> <ItemStyle CssClass="atext" HorizontalAlign="Center" Wrap="True" /> </asp:TemplateField> <asp:TemplateField > <ItemTemplate> <asp:Label ID="lblstateID2" runat="server" Tooltip='<%# Bind("2") %>'></asp:Label> <asp:CheckBox ID="chk2" runat="server" /> </ItemTemplate> <ItemStyle CssClass="atext" HorizontalAlign="Center" Wrap="True" /> </asp:TemplateField> <asp:TemplateField > <ItemTemplate> <asp:Label ID="lblstateID3" runat="server" Tooltip='<%# Bind("3") %>'></asp:Label> <asp:CheckBox ID="chk3" runat="server" /> </ItemTemplate> <ItemStyle CssClass="atext" HorizontalAlign="Center" Wrap="True" /> </asp:TemplateField> </Columns> </asp:GridView> </body>
MAK | Mark as Answer if this reply helps you | |
![]() MVP ASP/ASP.Net | ASP.Net Hosting : Host Depot | My Site : ASPSnippets |
![]() |
0 |
![]() |
Hi, try this script (additional parent() has been added),
<script type="text/javascript" language="javascript">
window.onload = function() { bindevent(); };
function bindevent() {
$("input[id$=chkAll]").bind("click", function(event) { checkboxHandler(event); });
}
function checkboxHandler(e) {
var name = "#"+e.target.id.toString();
var b = $(name)[0].checked;
$(name).parent().parent().siblings().children("input:checkbox").attr("checked", b);
}
</script>if it's not working, using firebug to check checkbox DOM, there might need to add another parent() in. give it another try.
![]() |
0 |
![]() |
thanx thanx thanx
finally it worked out , i m happy and fixing a bug on my bug list.
but please tell me the magic of this line
var row = obj.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;
![]() |
0 |
![]() |
No magic Just Finding parents
obj=your checkbox
span td tr tbody table td(GridView) tr(GridView)
var row = obj.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;
MAK | Mark as Answer if this reply helps you | |
![]() MVP ASP/ASP.Net | ASP.Net Hosting : Host Depot | My Site : ASPSnippets |
![]() |
0 |
![]() |
Thx
![]() |
0 |
![]() |