Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
XML
    <%@ Page Title="" Language="C#" MasterPageFile="~/home.Master" AutoEventWireup="true" CodeBehind="Home.aspx.cs" Inherits="employee_managment.Home" %>
     <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <link rel="stylesheet" href="https://code.jquery.com/ui/1.11.4/themes   /smoothness/jquery-ui.css"/>
    <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
    <script src="https://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
    <link href="style.css" rel="stylesheet" />
       <script>
        $(function () {
        $("#tabs").tabs({ active: 1 });
        });
        function NewWindow(empid)//this is used to open the popup window
        {
        var Open=window.open("AddEmployeeWebForm.aspx?empid="+empid,"EmployeeDetailsTab","Height=800px");
        }
        function EditLink(EmployeeID)//when we click on this this employee popup is opened
        {
            var Edit = window.open("AddEmployeeWebForm.aspx?empid=" + EmployeeID, "EditingEmployee", "Height=800px");

        }//select all is used to select all the data in the grid
        function SelectAllCheckboxes1(chk) {

            $('#<%=EmployeeDetailsGrid.ClientID%>').find("input:checkbox").each(function () {
                if (this != chk) {
                    this.checked = chk.checked;
                }
            });
        }

        function DeleteConfirmbox(val) {//is to delete the selected data from grid
            var arrCheckboxes;
            var checkboxSelector = "input[type='checkbox']";
            $("body").delegate(checkboxSelector, "click", function () {
                arrCheckboxes = $(checkboxSelector).map(function () {
                    return this.checked;//
                }).get();
            });



            // confirm meg check for delete
            var result = confirm('Are you sure delete Emp Record?');
            if (result) {

                // this is for get hdnvalue id
                var value = val.replace("DeleteEmpData", "hdnEmployyeID");

                $.ajax({
                    type: "POST",//akax is used to delete data

                    url: "Home.aspx/DeleteEmpData", // this for calling the web method function in cs code.
                    data: '{EmployeeID: "' + $("#" + value).val() + '" }',// empid value
                    dataType: "json",
                    success: OnSuccess,
                    failure: function (data) {
                        alert(data);
                    }


                });

                return false;
            }
        }

        // function OnSuccess
        function OnSuccess(response) {
            return false;
            if (response.d == 'true') {


            }

        }


     </script>
      </asp:Content>
      <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
      <asp:button id="backButton" runat="server" text="Back"OnClientClick="JavaScript:window.history.back(1);return false;" OnClick="backButton_Click"></asp:button>

      <div style="text-align:right">WELCOME{<asp:Label id="UserDetails" runat="server"></asp:Label>}</div>
      <div style="text-align:right"> <asp:Button CssClass="Button" ID="logout" Text="logout" runat="server" OnClick="logout_Click"></asp:Button></div>

     <div id="tabs" class="feature-tabs">//
        <ul>
                 <li><a href="#Client">Client</a></li>
                 <li><a href="#Employee">Employee</a></li>
       </ul>
          <div id="Client">
              <table style="height:500px">

        </table>

       </div>
      <div id="Employee">
      <table style="width:50%">//this is used to show the tabs button
      <tr>
            <td><asp:Button CssClass="Button"  ID="AddEmployee" Text="Add Employee" runat="server" OnClientClick="return NewWindow(0)" OnClick="AddEmployee_Click" ></asp:Button></td>
          <td><asp:Button  CssClass="Button" ID="DeleteEmployee" Text="Delete Employee" runat="server"  OnClientClick="javascript:DeleteConfirmbox();" ></asp:Button></td>
           <td><asp:Button  CssClass="Button" ID="Print" Text="Print" runat="server" OnClick="Print_Click" ></asp:Button></td>
          <td><asp:Button  CssClass="Button" ID="Refresh" Text="Refresh" runat="server" OnClick="Refresh_Click" ></asp:Button></td>

          </tr>

          </table>
            <br />
        <asp:GridView ID="EmployeeDetailsGrid" runat="server" AutoGenerateColumns="false" ShowHeaderWhenEmpty="true" DataKeyNames="EmployeeID" Width="100%" >
      <Columns>
          <asp:TemplateField>
              <HeaderTemplate>
                  <asp:CheckBox  ID="SelectAll"                                                                          onclick="javascript:SelectAllCheckboxes1(this);"runat="server">
             </asp:CheckBox>
              </HeaderTemplate>
              <ItemTemplate>
                  <asp:CheckBox ID="GridCheckBox" runat="server" />
              </ItemTemplate>
          </asp:TemplateField>
          <asp:BoundField DataField="EmployeeID"   HeaderText="ID" />
          <asp:BoundField DataField="SaveFirstName" HeaderText="Name" />
          <asp:BoundField DataField="SavePhone" HeaderText="Phone" />
          <asp:BoundField DataField="SaveZipCode" HeaderText="ZipCode" />
          <asp:BoundField DataField="Designation" HeaderText="Designation" />

          <asp:TemplateField HeaderText="Edit">
           <ItemTemplate >//hear will be the edit link
           <a href="#" id="EditLink" onclick="return EditLink(<%#Eval("EmployeeID") %>);">Edit</a>

           </ItemTemplate>
           </asp:TemplateField>

          </Columns>

       </asp:GridView>

      </div>


       <div style="height:500px"></div>
        </div>
        </asp:Content>



this is the code behind

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;

     namespace employee_managment
    {
    public partial class Home : System.Web.UI.Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (!this.Page.IsPostBack)//hear we bind the data to list
                {
                    EmployeeDetails emp = (EmployeeDetails)Session["ActiveUser"];
                    if (emp != null)
                        UserDetails.Text = emp.EmployeeName;
                    DataAccess access = new DataAccess();
                    List<AddEmployee> GetDetails = new List<AddEmployee>();
                    GetDetails = access.GetEmployeeDetails();
                    EmployeeDetailsGrid.DataSource = GetDetails;
                    EmployeeDetailsGrid.DataBind();


                }
            }
            catch (Exception)
            {

            }


        }

        protected void logout_Click(object sender, EventArgs e)//this is used to terminate the session
        {
            Session.Clear();
            Session.Abandon();
            Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1));
            Response.Cache.SetValidUntilExpires(false);
            Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.Cache.SetNoStore();
            Response.Redirect("login.aspx");
        }

        protected void backButton_Click(object sender, EventArgs e)
        {
            Session.Clear();
            Session.Abandon();
        }

        protected void AddEmployee_Click(object sender, EventArgs e)
        {

        }

        protected void DeleteEmployee_Click(object sender, EventArgs e)
        {

        }

        protected void Print_Click(object sender, EventArgs e)
        {

        }

        protected void Refresh_Click(object sender, EventArgs e)//when we click on refresh we again bind the grid view data
        {
            try
            {
                    DataAccess access = new DataAccess();
                    List<AddEmployee> GetDetails = new List<AddEmployee>();
                    GetDetails = access.GetEmployeeDetails();
                    EmployeeDetailsGrid.DataSource = GetDetails;
                    EmployeeDetailsGrid.DataBind();
            }
            catch (Exception)
            {

                throw;
            }
        }
        [System.Web.Services.WebMethod]
        public static string DeleteEmpData(int EmployeeID)
          {



          }


         }
     }
Posted
Comments
Richard Deeming 24-Aug-15 9:02am    
Was there supposed to be a question hiding in that code-dump?

1 solution

Your headertemplate will be like this
XML
<HeaderTemplate>
<asp:CheckBox ID="SelectAll" onclick="javascript:HeaderClick(this);" runat="server" />
</HeaderTemplate>

Then just use simple javascript function to select or deselect all the checkboxes in the gridview

C#
function HeaderClick(e)
        {
            var collection = document.getElementById('EmployeeDetailsGrid').getElementsByTagName('input');
            for (var i = 0; i < collection.length; i++) {
                if (collection[i].type.toUpperCase() == 'CHECKBOX')
                    collection[i].checked = e.checked;
            }
        }
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900