protected void Button3_Click(object sender, EventArgs e)
{
string strSQL = "";
for (int i = 0; i < this.GridView1.Rows.Count; i++)
{
string str = this.GridView1.Rows[i].Cells[1].Text.Trim();
if ((this.GridView1.Rows[i].FindControl("CheckBox1") as CheckBox).Checked == true)
{
strSQL += "select * from SYS_BPS_USERS where USER_Account ='" + str + "';";
}
}
这是后台获得checkbox选中的代码,我还想添加都没选则alert(“错误”)的方法
{
string strSQL = "";
for (int i = 0; i < this.GridView1.Rows.Count; i++)
{
string str = this.GridView1.Rows[i].Cells[1].Text.Trim();
if ((this.GridView1.Rows[i].FindControl("CheckBox1") as CheckBox).Checked == true)
{
strSQL += "select * from SYS_BPS_USERS where USER_Account ='" + str + "';";
}
}
这是后台获得checkbox选中的代码,我还想添加都没选则alert(“错误”)的方法
解决方案 »
- 难道就没人遇到过这样的问题
- webBrowser如何判断一个url真正加载完成,这个url页面中有ajax的调用
- C#模拟键盘输入
- 小菜又来问各位大哥。
- C#遇到的大难题,高手请进,在线等。
- 关于双面打印的奇怪问题
- 在.NET如何做报表设计器?诚征方案.
- 关于分页的问题
- 对String类的困惑!
- 熟悉Crystal Reports for Visual Studio .NET 的朋友请进,有个不算很难的问题请教
- 关于winform list=list跟list.addrang(list)的区别
- winform 里上传图片怎么做到如果图片存在就让他重选则或者把原来的覆盖,或者让他改名字之后再传上去。着急
<head runat="server">
<title></title>
<style type="text/css">
* { margin:0px; padding:0px;}
body{ font-size:12px;}
#header{ cursor:pointer;}
#header{line-height:25px; background:#ccc; cursor:pointer; border:1px solid #000;}
#content{ background:#ccc; border:1px solid #000;}
#content p{ line-height:25px;}
</style>
<script src="jquery/jquery-1.6.2.min.js" type="text/javascript"></script>
<script type="text/javascript" language="javascript">
$(function () {
//全选checkbox
$(":button[value=全选]").bind("click", function () {
$(":checkbox").attr("checked", true)//attr()更改属性方法
});
//全不选checkbox
$(":button[value=全不选]").bind("click", function () {
$(":checkbox").attr("checked", false)//attr()更改属性方法
});
//反选,先把兄弟选上,
$(":button[value=返选]").click(function () {
$(":checked").siblings().attr("checked", true).end().attr("checked", false); //反选,先把兄弟选上,
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div style="width:663px; margin-top:100px;height:222px;">
<p>
<input checked="checked" type="checkbox" />选择框1
<input checked="checked" type="checkbox" />选择框2
<input checked="checked" type="checkbox" />选择框3
<input type="checkbox" />选择框4
<input type="checkbox" />选择框5
<input type="checkbox" />选择框6
<input type="checkbox" />选择框7
<input type="checkbox" />选择框8
</p>
<p style=" margin-top:23px;">
<input style=" width:100px; height:25px;" type="button" value="全选" />
<input style=" width:100px; height:25px;" type="button" value="全不选" />
<input style=" width:100px; height:25px;" type="button" value="返选" />
</p>
</div>
</div>
</form>
</body>
</html>jquery
类似这种,放在gridview其实一样
System.Web.UI.WebControls.CheckBox cbox = (System.Web.UI.WebControls.CheckBox)GridView1.Rows[drv.RowIndex].FindControl("chbCheck");主要是第二句,你参考下,根据你的情况修改下就可以了
protected void Button3_Click(object sender, EventArgs e)
{
bool bl = false;
for (int i = 0; i < this.GridView1.Rows.Count; i++)
{
string str = this.GridView1.Rows[i].Cells[1].Text.Trim();
if ((this.GridView1.Rows[i].Cells[0].FindControl("CheckBox1") as CheckBox).Checked == true)
{
bl = true;
break; }
}
if (!bl)
{ Response.Write("<script language='javascript'>alert('错误');</script>");
return;
}
string strSQL = "";
for (int i=0;i < this.GridView1.Rows.Count; i++)
{
string str = this.GridView1.Rows[i].Cells[1].Text.Trim();
if ((this.GridView1.Rows[i].FindControl("CheckBox1") as CheckBox).Checked == true)
{
strSQL += "select * from SYS_BPS_USERS where USER_Account ='" + str + "';";
}
}谢谢啦!