c# 全选和批量修改

复制代码
//全选
function checkAll(){
var items = document.getElementsByTagName("input");
for(var i =0;i<items.length;i++){
if(items[i].type == "checkbox" && items[i].id.indexOf("CheckBox1")>0){
items[i].checked = document.getElementById("ctl00_ContentPlaceHolder1_GridView1_ctl01_CheckBox3").checked;
}
}
}

function checkAlls(){
var items = document.getElementsByTagName("input");
for(var i =0;i<items.length;i++){
if(items[i].type == "checkbox" && items[i].id.indexOf("CheckBox2")>0){
items[i].checked = document.getElementById("ctl00_ContentPlaceHolder1_GridView2_ctl01_CheckBox4").checked;
}
}
}
//批量修改删除
string ids = "";
//遍历所有数据行
for (int i = 0; i < GridView1.Rows.Count; i++)
{
CheckBox chk = GridView1.Rows[i].FindControl("CheckBox1") as CheckBox;
if (chk.Checked)
{
//通过主键获取
ids +="'"+ GridView1.DataKeys[i].Value.ToString()+"'" + ",";
}
}
if (ids.Length == 0)
{
Response.Write("<script>alert('您没有选择!!!')</script>");
return;
}
else
{
//去掉最后逗号
ids = ids.Substring(0,ids.Length-1);
//访问数据库
SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=GameCardSale;Integrated Security=True");
string sql = "Update UserInfo set UserRole=3 where UserId in ("+ids+")";
SqlCommand comm = new SqlCommand(sql,conn);
conn.Open();
int num = comm.ExecuteNonQuery();
conn.Close();
if (num > 0)
{
Response.Write("<script>alert('会员通过审核成功!!!')</script>");
}
else
{
Response.Write("<script>alert('网络繁忙!!请稍后再试!!!')</script>");
}
GridView1.DataBind();


}
复制代码

 

posted @   卡玛兹  阅读(458)  评论(0编辑  收藏  举报
编辑推荐:
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 张高兴的大模型开发实战:(一)使用 Selenium 进行网页爬虫
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
你好
点击右上角即可分享
微信分享提示