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/ ...
随机推荐
- MySQL中四舍五入的实现
MySQL四舍五入的实现 文章主要描述的是MySQL四舍五入的实际应用, 以及在其实际操作中的值得我们大家注意的事项与其实际应用代码的描述,以下就是文章的主要内容的详细描述,望大家在浏览之后会对其 ...
- 通过DOM节点操作来获取表单信息
这是之前突发奇想地用dom节点的关系来操作表单的故事.. 事情的经过是这样的,大概就是一个平台注册后有留言功能,管理员登录之后可以对这些留言进行回复.这个页面呢,就是通过foreach获取到数据库里的 ...
- rh6安装oracle11g+ASM
安装步骤我这里略过,主要说下安装过程中遇到到问题或重要步骤: 1.UDEV绑定: for i in b c d e ;doecho "KERNEL==\"sd*\", B ...
- SmartWiki文档在线管理系统简介
简介 SmartWiki是一款针对IT团队开发的简单好用的文档管理系统.可以用来储存日常接口文档,数据库字典,手册说明等文档.内置项目管理,用户管理,权限管理等功能,能够满足大部分中小团队的文档管理需 ...
- MVC 為頁面的list資料重新命名
function ReBookFileName() { $("#div_sortable").find("li[ ...
- php关闭错误提示
今天调试phalcon的一个接口时候碰到如下提示: Deprecated: mongogo::mongogo(): The Mongo class is deprecated, please use ...
- CSS BOX模型
对于box模型概念的理解以及它与决定元素最终尺寸的方式有何关系,是理解如何设定网 页上的元素位置的基础.box模型应用到块级元素.一个随之而来的概念,内联布局模型 定义了如何设定内联元素的位置. 对于 ...
- _Dispose(typeinfo,pointer ); 不知道说的是什么? 感觉会有用, 留待以后研究
[传说]晓不得2013(26562729) 16:45:41别人把文章发出来,说明就是验证过的.[潜水]ひㄨㄨ那个ㄨㄨ(1548253108) 16:46:23[潜水]ひㄨㄨ那个ㄨㄨ(15 ...
- oc中的枚举定义
typedef NS_ENUM(类型,枚举名){ 枚举名+值名, 枚举名+值名,}; 该方法定义的枚举,OC会自动把其转换成合适当前版本的枚举.如果枚举值可合并的话 NS_E ...
- 先进先出集合queue
先进先出集合queue Enqueue添加到集合最后 Dequeue移除集合第一个对象并返回