javascript: check all check box in a perticular row , when i check a checkbox i that perticuler row

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
lalitsinghnegiaspnet
4/14/2009 9:28:29 AM
asp.net.web-forms 93655 articles. 6 followers. Follow

25 Replies
983 Views

Similar Articles

[PageSpeed] 51

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
XIII
4/14/2009 9:57:03 AM

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>
 
MAKMark as Answer if this reply helps you
MVP ASP/ASP.Net
MVP ASP/ASP.Net
ASP.Net Hosting : Host DepotMy Site : ASPSnippets
0
mudassarkhan
4/14/2009 10:05:53 AM

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
lalitsinghnegiaspnet
4/14/2009 10:40:06 AM

kindly read the question carefully, ur code is not relevent to my question

0
lalitsinghnegiaspnet
4/14/2009 10:42:53 AM

Hi,

Check out these links

http://aspadvice.com/blogs/azamsharp/archive/2006/10/26/Select-All-Checkboxes-while-Paging-in-GridView.aspx

http://www.codedigest.com/Articles/ASPNET/132_GridView_with_CheckBox_%E2%80%93_Select_All_and_Highlight_Selected_Row.aspx

 

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
susain
4/14/2009 11:06:29 AM

hi Farooq

Read  my question again carefully .

0
lalitsinghnegiaspnet
4/14/2009 11:36:47 AM

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
XIII
4/14/2009 11:40:34 AM

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
seekerwoo
4/14/2009 12:12:56 PM

 Sorry, please amend my previous solution: add attributes runat="server" to all checkbox to make it possible to generate unique client id.

 Thanks 

0
seekerwoo
4/14/2009 12:21:02 PM

hi,

 where can i find the script file with u have used ?

src="scripts/jquery-1.3.2.js"

0
lalitsinghnegiaspnet
4/14/2009 12:33:03 PM

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
seekerwoo
4/14/2009 12:38:07 PM

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
lalitsinghnegiaspnet
4/14/2009 12:40:47 PM

hi,

i have downloaded the script file but still the code is not working and the problem is not resolved , kindly suggest

0
lalitsinghnegiaspnet
4/14/2009 12:51:59 PM
0
XIII
4/14/2009 12:53:09 PM

Hi,

lalitsinghnegiaspnet:
i have downloaded the script file but still the code is not working and the problem is not resolved , kindly suggest

Can 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
XIII
4/14/2009 12:56:44 PM

 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
seekerwoo
4/14/2009 1:01:36 PM

 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
kavita_khandhadia
4/14/2009 1:04:23 PM

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
seekerwoo
4/14/2009 1:14:52 PM

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
lalitsinghnegiaspnet
4/14/2009 1:16:08 PM

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
4/14/2009 1:34:11 PM

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>
 
MAKMark as Answer if this reply helps you
MVP ASP/ASP.Net
MVP ASP/ASP.Net
ASP.Net Hosting : Host DepotMy Site : ASPSnippets
0
mudassarkhan
4/14/2009 1:50:12 PM

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
seekerwoo
4/14/2009 2:04:20 PM

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
lalitsinghnegiaspnet
4/14/2009 2:09:19 PM

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;


MAKMark as Answer if this reply helps you
MVP ASP/ASP.Net
MVP ASP/ASP.Net
ASP.Net Hosting : Host DepotMy Site : ASPSnippets
0
mudassarkhan
4/14/2009 2:16:28 PM

Thx

0
lalitsinghnegiaspnet
4/14/2009 2:30:52 PM
Reply:

Similar Artilces:

Check All Check Box While Check Header CheckBox
 hello...I have two grid on same page...both grid contains header checkbox and item checkbox i want that if use check header checkbox then all item check box checked,i have javascript for this functinality but problem is that when i click on header check box of first grid then checkbox of second grid also checked that i dnt want i want to perform this operation on one grid at one time.i have attache my script also...plz help me....thanks<script type="text/javascript">        function SelectAll(ID)      &nbs...

passing of values of each row into javascript function on check box check in gridview
i had a HTML hidden field in item template of gridview which is bind with a column "jobid" from tha database and a checkbox in each row.on header template of gridview i had a check box called "checkall" which is used for checking all the check boxes in the grid. my problem is -- i want to retrive the jobid of each row on the "checkall" click in the java script . <asp:TemplateField > <ItemStyle Width="9%" /> <EditItemTemplate> <asp:CheckBox ID="CheckBox1" runat="server" /> </EditItemTemplate> ...

checking checkbox is checked or not using checkbox.checked
Hi,my checkbox is<asp:CheckBox ID="Chkcity" runat="server" Text="My own city"  OnCheckedChanged="EventHandler"/>code behind: Private Sub Chkcity_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Chkcity.CheckedChangedif (Chkcity ...............)end if End SubERROR    'EventHandler' is not a member of 'ASP.bpoaddjob_aspx'.    Please Mark the post as "ANSWER" if it helps you I think it should be like this:<asp:CheckBox ID="Chkcity"...

passing of values of each row into javascript function on check box check in gridview #2
thanks for the reply but still i am facing a problem ---- how to get the checkbox value (checked/uncheck) present in the item template in the same java script function.if i  am checking the "checkall" checkbox in the gridview header template, i should get all the check box checked in the itemtemplate field and "jobid" value should go inside hidden field and while unchecking the "checkall" ,all the itemtemlate checkbox should uncheck.   if any of the checkbox in the itemtemplate is unchecked it should be removed from the hidden field.plzzzz He...

how to check all the row level checkbox when header level checkbox is checked
hello i m working on one site which requires the functionality like yahoo, that is when we check header level check box then all row level checkbox is checked.i m sending my code here....<script language="javascript" type="text/javascript">        function Check(chk)        {          alert("abc");            if(document.form1.HeaderLevelCheckBox.checked==true)    ...

How do I set a checkbox to checked when another checkbox in a DG row is checked?
I have a datagrid with rows of labels, textboxes, and checkboxes.  These rows show information about customers.  When a user checks one of the checkboxes, I need the other textbox to become checked as well.  When the user unchecks the checkbox, nothing should happen.  See code below.  Any ideas?  The trick is finding the checkbox control for that specific row.  Thanks!!!! <asp:GridView ID="CustomFieldsGridView" width="100%" runat="server" AutoGenerateColumns="False" DataKeyNames="CustomizableFieldCode" DataSourceID="CustomFieldsObjectDataSource" ShowHe...

In DataGrid which all rows the user has checked the Check Box.....?
hai everyone I am not all that familiar with programing with DataGrid with ASP.net in C# so i have some problem.........which are as follows...... i am making use of Check Box inside a Templet Column within a DataGrid. But the problem is how can i know in which all rows the user has checked the Check Box.....? Basiclly i want to manupulate the data in which the check Box is Checked when the page is submitted. Thanks in advance keep smiling austin What you could do is in your submission event you can do something like this: ...

Need help adding dynamic check boxes to rows returned to a datagrid/datarepeater/etc and checking for values in the checkbox
Here is my scenario,I have Users that have Friends.  They can add friends, and remove friends.I want to populate an ASP.Net control (data grid, repeater, whatever is best) with the friend's name and then provide a column with checkboxes.  The submit button will perform the Remove.When I Remove, I want to iterate through each row and if the row has a checked checkbox, grab the friend's ID from that line and stuff it into a string for later use (delete query).Can anyone make suggestions on how to code this, point me to some articles, or offer any other suggestions?Thanks for the help...

how to check if a check box created in runtime checked or not?
I have a webform that have mutiple collectios of check boxes created on run time ( database driven) what is the best way to loop between them and get which ones has been checked by a user and save the results back to the database below a portion of my code. i am adding the checkbox to cell table which added to a row, then to a table, finlally the table added to a place holderwhile (drProfileList.Read()) {HtmlTableRow tr = new HtmlTableRow(); HtmlTableCell tc = new HtmlTableCell();CheckBox chkbox = new CheckBox(); chkbox.ID = drProfileList["RoleID"].ToString();chkbox.T...

How to check how many check boxes are checked in the gridview
I am trying to make a javascript client fucntion to restrict no more then two rows could be selectedI have following in the itemtemplate of the gridview [although it is telerik control but same technique should be applied] <radG:GridTemplateColumn UniqueName="chkCheck">                    <HeaderStyle  HorizontalAlign="Right" />                    <HeaderTempla...

Check in
Hi all. I am migrating from PB 7.0 to PB 10.5, After migrating my first application i am trying to work on my first window but i'am not able to find out the way to CHECK it OUT. Wher do i can find "check out/check in" functions ?? TIA Mario Parietti What source control are you using? Have you configured it? Right click on your Workspace and check the source control tab to see if you've got it set up. "Mario Parietti" <mparietti@intercad.ch> wrote in message news:451283e0$1@forums-1-dub... > Hi all. > I am migrating from PB...

multiple rows delete in griview when multiple check boxes are checked
hi  to all, with this code single row is deleting when check box is checked in corresponding row..but multiple rows are not deletingplz check this code ..  <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1"         Style="z-index: 100; left: 295px; position: absolute; top: 124px" Height="142px" Width="468px" >         <Columns>       &nb...

Check In/Check out
I am using PowerBuilder 9. The undo check out is right next to the check in. This is a big problem! I so easy to select Undo check out and lose all of your changes. I lost 8 hours of work yesterday because of it. I know I should be more careful. However, there should be a "Are you sure" some where also. PLEASE FIX!!!!!!!!!!!!! -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/ This isn't the tech support line, it's an end-user forum. If you want to report a bug, use CaseXpress and either open a case or report a bug ...

Check out/check in
Hello How can i use the process check out/check in in PowerBuilder 8.0.3 ? We work in network. The Source Control is PB Native. I don't understand what is the parameters of Source Control ? Thank you Have you looked the PB8 User's guide? Chapter 3 talks about source control. -- Evita Chapa Senior Systems Analyst II Command Technologies Inc. <Herv� Bareth> wrote in message news:3f69ba0a.592b.846930886@sybase.com... > Hello > > How can i use the process check out/check in in PowerBuilder > 8.0.3 ? We work in network. The Source Control is PB Na...

Web resources about - javascript: check all check box in a perticular row , when i check a checkbox i that perticuler row - asp.net.web-forms

Resources last updated: 11/23/2015 7:06:37 PM