如何获得全选的值 在GridView中用户ID为1,2,3,4我点击全选后。我点击全选后怎么取得用户ID所有的值。我只会在GridView中取单个的值。取全部的值是怎么弄? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 foreach (GridViewRow row in GridView){ //取出每一行中的ID} 你要用for循环找到你的控件 //全选和反选 如果你要取值雷同 protected void ckbAll_CheckedChanged(object sender, EventArgs e) //注ckbAll为你全选的那个复选框控件 { CheckBox ckbAll = (CheckBox)sender; if (ckbAll.Checked == true) { for (int i = 0; i < this.gvManage.Rows.Count; i++) //注gnManage为你的GridView { CheckBox ckbSend = (CheckBox)this.gvManage.Rows[i].Cells[0].FindControl("ckbOne"); if (ckbSend != null) { ckbSend.Checked = true; } } } else { for (int i = 0; i < this.gvManage.Rows.Count; i++) { CheckBox ckbSend = (CheckBox)this.gvManage.Rows[i].Cells[0].FindControl("ckbOne"); if (ckbSend != null) { ckbSend.Checked = false; } } } } 还有要注意ckbOne为你要找的那个控件的名称 参考一下下面的代码,是一个用来获取所有选中ID的,方法返回了一个ID组成的字符串,可以在使用的时候拆分开来: private string getSelectedIDS() { string strDeleteIDS = null; GridView grid = this.grdBooks; for (int i = 0; i < grid.Rows.Count; i++) { CheckBox checkBox = grid.Rows[i].FindControl("checkBox") as CheckBox; if (checkBox != null && checkBox.Checked) { strDeleteIDS+= grid.DataKeys[i].Value + "|"; } } return strDeleteGuid; } 补充LS的:GridView用到了DataKeys,需要设置DataKeyNames属性。 .net的DOM操作和js中的DOM操作为什么不一样? 【马上结贴】页面传值 weboffice.ocx 若干年没来,技术排名还没过千阿?撒分,都来接! 这样的项目大概多少钱? 各位老大,请问怎么用.NET生成静态页面? 一个多语言的问题 asp.net页面更新问题 我动态创建了一个xml文件怎样往里加文档类型<?xml version=1.0 encoding="utf-8"> 请问在ASP.Net中如何实现一个子页面控制另一个主页面刷新呢? 有关IE7下使用HTMLEditor的问题 企业库(EnterpriseLibrary)执行带参数的存储过程
{
//取出每一行中的ID
}
//全选和反选
如果你要取值雷同
protected void ckbAll_CheckedChanged(object sender, EventArgs e) //注ckbAll为你全选的那个复选框控件
{
CheckBox ckbAll = (CheckBox)sender;
if (ckbAll.Checked == true)
{
for (int i = 0; i < this.gvManage.Rows.Count; i++) //注gnManage为你的GridView
{
CheckBox ckbSend = (CheckBox)this.gvManage.Rows[i].Cells[0].FindControl("ckbOne");
if (ckbSend != null)
{
ckbSend.Checked = true;
}
}
}
else
{
for (int i = 0; i < this.gvManage.Rows.Count; i++)
{
CheckBox ckbSend = (CheckBox)this.gvManage.Rows[i].Cells[0].FindControl("ckbOne");
if (ckbSend != null)
{
ckbSend.Checked = false;
}
}
} }
{
string strDeleteIDS = null;
GridView grid = this.grdBooks;
for (int i = 0; i < grid.Rows.Count; i++)
{
CheckBox checkBox = grid.Rows[i].FindControl("checkBox") as CheckBox;
if (checkBox != null && checkBox.Checked)
{
strDeleteIDS+= grid.DataKeys[i].Value + "|";
}
}
return strDeleteGuid;
}
GridView用到了DataKeys,需要设置DataKeyNames属性。