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/ ...
随机推荐
- 给日志添加“复制”效果
给日志添加如上效果的实现方法: 在日志编辑页面,源代码中,添加如下代码,包裹住 目标内容style1: <div class="cnblogs_code"><di ...
- leetcode 141
141. Linked List Cycle Given a linked list, determine if it has a cycle in it. Follow up:Can you sol ...
- PIC32MZ tutorial -- Output Compare
Output Compare is a powerful feature of embedded world. The PIC32 Output Compare module compares the ...
- SQL Server添加MDW性能监控报表(转载)
10.2 Data Collector与MDW Data Collection功能是SQL SERVER 2005版本提供的数据库监控报表的功能,通过定时地对数据库的语句运行情况,服务器各种资源的监控 ...
- java 字节数组转int
4字节数组转int类型 小端模式 /** * 数组转int类型 * * @param src * @return */ public static int bytesToInt(byte[] src) ...
- SQL SELECT语句
基本SQL SELECT语句 1. 下面的语句是否可以执行成功 select ename , job , sal as salary from emp; 2. 下面的语句 ...
- 3.openssl speed和openssl rand
(1).openssl speed 测试加密算法的性能. 支持的算法有: openssl speed [md2] [mdc2] [md5] [hmac] [sha1] [rmd160] [idea-c ...
- SQL 2012 alwayson设置只读路由
ALTER AVAILABILITY GROUP [sqlmaxiangqianbd] MODIFY REPLICA ON N'maxiangqian1' WITH (SECONDARY_R ...
- gitlab 配置
一.Gitlab的使用 具体步骤: 1.打开 Git Bash,输入~ssh -keygen 然后一直回车,直至出现图片上的内容 1) 2) 2.然后自动生成.ssh文件夹,双击文件夹 1) 2) ...
- QT 使用jsoncpp
QT 使用jsoncpp 编译jsoncpp 编译前先安装好python,scons,解压jsoncpp到目录e:\jsconcpp,查看目录下的readme,有关于编译的说明的,根据说明做相应操作就 ...