我有一个网格,其中一列是复选框,复选框的标题用于选择所有 [英] i am having a grid and one of the column is checkbox and the header of the checkbox is used to select all
本文介绍了我有一个网格,其中一列是复选框,复选框的标题用于选择所有的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<%@ 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)
{
}
}
}
推荐答案
(function () {
(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) {
("#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']\";
('#<%=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']";
这篇关于我有一个网格,其中一列是复选框,复选框的标题用于选择所有的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文