Friday, 4 October 2013

How to select all the Checkboxes in Gridview by clicking on Checkbox in HeaderText in ASP.NET using Javascript

Hi friends, in this article I will explain about How to select all the Checkboxes in Gridview by clicking on Checkbox in HeaderText in ASP.NET using Javascript 
<html xmlns="">
<head runat="server">
    <title>Select all checkboxes in GridView in ASP.NET </title>
    <script type ="text/javascript" language ="javascript" >
        function HeaderSelect(selval) {
            if (selval == true) {
            else {
        function CheckUncheckall(selval) {
            var parentcontrol = document.getElementById('<%= GridView1.ClientID %>');
            var inputctrls = parentcontrol.getElementsByTagName("input");

            for (var i = 0; i < inputctrls.length; i++) {
                if (inputctrls[i].type == 'checkbox') {
                    inputctrls[i].checked = selval;
    <form id="form1" runat="server">
        <asp:GridView ID="GridView1" runat="server">
          <HeaderStyle BackColor="#E9F3F8" Height="40px" />
          <RowStyle BorderColor="#DDDDDD" HorizontalAlign="Left" VerticalAlign="Middle" Height="40px" />
          <AlternatingRowStyle Height="40px" BackColor="#F7FAFC" />
          <Columns >
            <HeaderStyle HorizontalAlign="Center" Width="45" BorderColor="#DDDDDD"></HeaderStyle>
                  <input name="Cbx_QRHeader" onclick="HeaderSelect(this.checked);" type="checkbox">
                  <input type="checkbox" name="Cbx_Cid" value='<%#DataBinder.Eval(Container.DataItem, "userid")%>%>'>
            <ItemStyle HorizontalAlign="Center" BorderColor="#DDDDDD" />
            <HeaderStyle HorizontalAlign="Center" BorderColor="#DDDDDD" Width="30px" />

In C#.NET:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
public partial class AutoComplete : System.Web.UI.Page
    SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["con"].ConnectionString);
    protected void Page_Load(object sender, EventArgs e)
        SqlCommand cmd = new SqlCommand("select * from user_data", con);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        GridView1.DataSource = ds;


No comments:

Post a Comment

© 2012-2018 All Rights Reserved.
The content is copyrighted to Kishore and may not be reproduced on other websites without permission from the owner.