GridView CheckBox 全选
GridView CheckBox 全选
<script type="text/javascript">
$(function () {
$("#allCheck").click(function () { //点击全选按钮
if ($(this).prop("checked")) {
$("#GridView1 :checkbox").prop("checked", true);
} else {
$("#GridView1 :checkbox").prop("checked", false);
}
});
$("#GridView1 :checkbox:gt(0)").click(function () {
var chItem = $("#GridView1 :checkbox:gt(0)");
var isAllCheck = true;//是否全部选中了
for (var i = 0; i < chItem.length; i++) {
if (!$(chItem[i]).prop("checked")) {
isAllCheck = false;
break;
}
}
$("#allCheck").prop("checked", isAllCheck);
});
});
</script>
<asp:GridView ID="GridView1" runat="server" CssClass="dataTable" DataKeyNames="ID">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<input type="checkbox" id="allCheck" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="操作">
<ItemTemplate>
<a href="CreateCompanyShop.aspx?cm=<%#Eval("COMPANY") %>" title="详情">
<img src="../images/明细.png" width="20" title="详情" height="20" border="0" /></a>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
// 获取选中的ID集合
private List<string> GetCheckRowIds()
{
//获取复选框被选中的行id
List<string> lst = new List<string>();
foreach (GridViewRow row in GridView1.Rows)
{
CheckBox cb = row.Cells[0].FindControl("CheckBox1") as CheckBox;
if (cb.Checked)
{
lst.Add(GridView1.DataKeys[row.RowIndex].Value.ToString());
//ids += "'" + GridView1.DataKeys[row.RowIndex].Value + "',";
}
}
return lst;
}
public bool DeleteCMShopByIdList(List<string> idList)
{
string ids = string.Empty;
foreach (string item in idList)
{
ids += "'" + item + "',";
}
ids = ids.Trim(',');
string sql = "DELETE Company_Shop WHERE ID IN(" + ids + ");";
SqlTransaction tran = dbhelper.GetTransAction();
try
{
dbhelper.ExcuteNonequery(sql, tran);
tran.Commit();
return true;
}
catch (Exception)
{
tran.Rollback();
}
finally
{
tran.Dispose();
}
return false;
}
//TWO
private string GetCheckRowIds()
{
//获取复选框被选中的行id
string ids = string.Empty;
foreach (GridViewRow row in GridView1.Rows)
{
CheckBox cb = row.Cells[0].FindControl("CheckBox1") as CheckBox;
if (cb.Checked)
{
ids += "" + GridView1.DataKeys[row.RowIndex].Value + ",";
}
}
if (ids != string.Empty)
{
ids = ids.TrimEnd(',');
}
return ids;
}
protected void btnSure_Click(object sender, EventArgs e)
{
string ids = GetCheckRowIds();
if (ids == string.Empty)
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "提示", "<script>alert('你没有选择任何选项')</script>");
return;
}
int undoCount = 0;
string[] idArray = ids.Split(',');
IDbTransaction tran = ConnectStringConfig.GetTran();
try
{
foreach (string id in idArray)
{
string strStatus = "";
string sql = "select ID,TYPE,STATUS from tasks_direct where id = " + id + "";
DataTable dttask = dbHelper.GetDataTable(sql);
foreach (DataRow dr in dttask.Rows)
{
strStatus = dr["STATUS"].ToString();
if (strStatus == "00")
{
boTaskDirect.ConfirmMove(dr["ID"].ToString(), boTaskDirect.TblTaskDirect.WEIGHT.Value, true, tran);
undoCount++;
}
}
}
tran.Commit();
}
catch (Exception ex)
{
tran.Rollback();
Response.Redirect(SysConfig.ErrorPage + ex.Message);
}
finally
{
tran.Dispose();
}
string message = undoCount.ToString() + " 个任务确认成功!";
Page.ClientScript.RegisterStartupScript(this.GetType(), "提示", "<script>alert('" + message + "')</script>");
Paginationer.BindData();
}
GridView CheckBox 全选的更多相关文章
- TreeView checkbox 全选
在使用TreeView 控件 ,进行权限管理的时候,需要使用 checkbox全选. 勾选父节点,子节点全部选中.取消父节点,子节点不选中. 勾选子节点,父节点也选中. 以下是在使用的例子: < ...
- JS checkbox 全选 全不选
/* JS checkbox 全选 全不选 Html中checkbox: <input type="checkbox" name="cbx" value= ...
- checkbox全选,反选,取消选择 jquery
checkbox全选,反选,取消选择 jquery. //checkbox全部选择 $(":checkbox[name='osfipin']").each(function(){ ...
- js初学—实现checkbox全选功能
布局如下: <p ><input type="checkbox" id="che1"/>全选</p><div id=& ...
- checkbox全选与反选
用原生js跟jquery实现checkbox全选反选的一个例子 原生js: <!DOCTYPE html> <html lang="en"> <hea ...
- angularjs实现 checkbox全选、反选的思考
之前做了一周的打酱油测试,其实感觉其实测试也是上辈子折翼的天使. 好长时间没写代码,感觉好多都不会了. 感谢这周没有单休,我能看熬夜看奥运了.我能有时间出去看个电影,我能有时间出去逛个商城,我能有时间 ...
- 利用jQuery实现CheckBox全选/全不选/反选
转自:http://www.cnblogs.com/linjiqin/p/3148259.html jQuery有些版本中实现CheckBox全选/全不选/反选会有bug,经测试jquery-1.3. ...
- jquery数组之存放checkbox全选值示例代码
使用jquery数组可以存放checkbox全选值,下面有个不错的示例,感兴趣的朋友可以参考下. 复制代码代码如下: <input type="checkbox" id=&q ...
- jQuery实现CheckBox全选、全不选
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
随机推荐
- yum 部署nginx
第一步,在/etc/yum.repos.d/目录下创建一个源配置文件nginx.repo: cd /etc/yum.repos.d/ vim nginx.repo 填写如下内容: [nginx ...
- Blackfin DSP(二):寄存器操作与GPIO
BlackfinDSP的寄存器是通过指针操作的,与51.ARM等MCU一样,通过“或”操作来置1,通过“与”操作清零. 在DSP上最简单的外设非IO口莫属,但是由于其功能强大,远非一般IO口可比,因此 ...
- uboot和内核波特率不同
uboot和内核波特率不同,在uboot启动后,修改uboot参数: set bootargs 'noinitrd root=/dev/mtdblock3 init=/linuxrc console= ...
- 在win server 2003上安装SQL Server 2008的步骤
1.安装Microsoft .NET Framework 3.5 Service Pack 1,下载地址:http://www.microsoft.com/zh-cn/download/confirm ...
- C语言初始化——栈的初始化
栈是一种具有后进先出性质的数据组织方式,也就是说后存放的先取出,先存放的后取出.栈底是第一个进栈的数据所处的位置,栈顶是最后一个进栈的数据所处的位置. 1.满栈与空栈 根据SP指针指向的位置,栈可以分 ...
- 纸上谈兵:伸展树(splay tree)
作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! 我们讨论过,树的搜索效率与树的深度有关.二叉搜索树的深度可能为n,这种情况下,每次 ...
- javascript高级程序设计--笔记01
概述 JavaScript的实现包含三个部分: 1 核心(ECMAScript) 提供核心语言功能 2 文档对象模型(DOM) 一套提供了访问以及操作网页内容的API 3 浏览器对象模型( ...
- COM的永久接口
COM的永久接口
- C语言基础_2
scanf函数可以从键盘上读取数据并记录到变量中.为了使用这个函数也需要在文件开头使用如下的预处理指令#include <stdio.h>scanf函数使用的时候所需要的初始数据和prin ...
- Docker上运行dotnet core
下载microsoft/dotnet镜像 运行命令: docker pull microsoft/dotnet 如果没有使用阿里镜像加速的,参照这篇先配置好再跑上面命令: http://www.cnb ...