在.aspx的<title></title>标签下添加如下脚本:
<script type="text/javascript" language="javascript">
function SelectAllCheckboxes(spanChk)
{
var oItem = spanChk.children;
var theBox=(spanChk.type=="checkbox")?spanChk:spanChk.children.item[0];
xState=theBox.checked;
elm=theBox.form.elements;
for(i=0;i<elm.length;i++)
if(elm[i].type=="checkbox" && elm[i].id!=theBox.id)
{
if(elm[i].checked!=xState)
elm[i].click();
}
}
</script>
在GridView中的模板列添加如下代码:
<asp:TemplateField>
<HeaderTemplate>
<input id="chkall" type="checkbox" onclick="SelectAllCheckboxes(this);" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chk" runat="server" />
</ItemTemplate>
<HeaderStyle CssClass="table_head" />
<ItemStyle Width="15px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="PersonId" Visible="False">
<ItemTemplate>
<asp:Label ID="lblPersonId" runat="server" Text='<%# bind("PersonId") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
在后台通过遍历GridView中的行来计算选中行的总数
int count=0;
foreach (GridViewRow gvr in PersonGridView.Rows)
{
bool isChecked = ((CheckBox)gvr.Cells[0].FindControl("chk")).Checked;
if (isChecked)
{
int iPersonId = Int32.Parse(((Label)gvr.Cells[1].FindControl("lblPersonId")).Text);
string strSql = "DELETE SYS_PERSON WHERE PersonId=@PersonId";
SqlConnection con = new SqlConnection(SqlHelper.ConnectionString);
SqlCommand cmd = new SqlCommand(strSql, con);
cmd.Parameters.Add("@PersonId",SqlDbType.Int);
cmd.Parameters["@PersonId"].Value = iPersonId;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
count++;
}
}
分享到:
相关推荐
C#_winform_GridView_CheckBox_多选_全选
gridview编辑删除,checkbox单选全选 数据库自行配置
改进gridView的单选和多选功能 实现全选和取消全选功能
asp.net GridView中的checkbox实现前台全选或取消全选
几天为了改变客户端grid的全选效率问题,详细研究了ext中grid的全选和gridview中通过脚本实现的全选效率,总结一下,供大家参考,有错误的地方,希望大侠指正,小弟献丑了。
GridView实现多选,全选,反选功能
获取GridView中Checkbox的值
ASP.NET GridView中两种全选方法.txt
ExpandableListView中group和child自定义视图带CheckBox,实现child全选、部分选中功能,同时实现类似邮件群发的用户选择功能,选中的用户在EditText中显示,点击后移除. 更新: 1. ExpandableListView勾选后生成的...
GridView和CheckBox可实现功能定制
GridView中加上CheckBox 的全选功能的代码,需要的朋友可以参考一下
GridView中checkbox全部选中实现代码,即单击顶部的全选checkbox,全选所有checkbox,全选所有行。
GridView js实现全选 (分页保持选择状态) GridView js实现全选 (分页保持选择状态)
ASP.NET Gridview checkbox全选与全不选实现代码,其实原理就是利用js来实现的,但需要简单的设置下回传。
* GridView通过div分页 * 将数据一次性加载到页面 * 减少访问服务器频率 * checkbox全选
<input id="cbAll" type="checkbox" onclick="GetAllCheckBox(this)" />全选 function GetAllCheckBox(CheckAll) { var items = document.getElementsByTagName("input"); for(i=0; i;i++) { if(items[i]....
GridView与CheckBox结合
GridView 第一列CheckBox全选!postBack和JS方式
GridView和CheckBox结合
GridView结合CheckBox实现多条删除 有疑问 请发我邮箱 zhaobin_sky@163.com