今天在Repeater控件中碰到一个全选的操作,于是上网查了一下,找到一个觉得比较好,便记录下来,

界面代码简化之后(全选操作):

  <script type="text/javascript">
     function SelectAll(parentChk, ChildId, bigControlID) {
var oElements = document.getElementsByTagName("INPUT");
var bIsChecked = parentChk.checked; for (i = 0; i < oElements.length; i++) {
if (IsCheckBox(oElements[i]) && IsMatch(oElements[i].id, ChildId, bigControlID)) {
oElements[i].checked = bIsChecked;
}
}
}
function IsMatch(id, ChildId, controlID) {
var sPattern = '^' + controlID + '_+.*' + ChildId + '$';
var oRegExp = new RegExp(sPattern);
if (oRegExp.exec(id))
return true;
else
return false;
} function IsCheckBox(chk) {
if (chk.type == 'checkbox') return true;
else return false;
}
</script> <asp:Repeater ID="Repeater_xx" runat="server">
<HeaderTemplate>
<table>
<tr>
<th>选项</th>
<th>数据</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:CheckBox ID="CheckBox_ID" runat="server" Checked="false" />
</td>
<td>
<asp:Label runat="server" ID="Label_ID" Text='<%#Eval("Label_ID")%>'></asp:Label>
</td>
<tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater> <asp:CheckBox runat="server" ID="CheckBoxCz" Text="全选/反选" onclick='SelectAll(this,"CheckBox_ID","Repeater_xx")'/>

<input class="anniu" id="input_gs" type="submit" runat="server" onserverclick="Gssubmit_Click" value="操作" />


后台根据选中项获取当前行的数据然后进行操作

 public void Gssubmit_Click(object sender, EventArgs e)
{
for (int i = ; i < Repeater_xx.Items.Count; i++)
{
//获取复选框
CheckBox cb = (CheckBox)rpt_Paper.Items[i].FindControl("CheckBoxCz");
//判断是否被选中
if(cb != null && cb.Checked == true)
{
Label id = (Label)rpt_Paper.Items[i].FindControl("Lable_ID");
//获取该行ID
int ID= Convert.ToInt32(Id.Text);
//相应操作
......
}
}
}
        

asp.net关于Repeater控件中的全选,批量操作的更多相关文章

  1. asp.net 在repeater控件中加按钮

    在repeater中加入方法有两种方法: 第一种:是对repeater控件的行添加OnItemCommand事件,添加方法也是有两种 1.在设计页面中,选中repeater控件右击==>属性== ...

  2. asp.net GridView控件中诗选全选和全不选功能

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...

  3. 在Repeater控件中使用if语句

    原文:在Repeater控件中使用if语句 .Afr_ARTICLE_TITLE { font: NORMAL BOLD 14px "Tahoma"; } .Afr_CONTENT ...

  4. ASP.NET- 查找Repeater控件中嵌套的控件

    如何在Repeater的HeaderTemplate和FooterTemplate模板中寻找控件?在Repeater的ItemTemplate模板中的控件,我们可以用Items属性来遍历行并用Find ...

  5. 获取不到Repeater控件中的CheckBox选中状态

    写在前面的话:在做一个项目的时候,需要使用到Repeater控件,并且在Repeater控件内放置了CheckBox控件来标志需要删除的行,选中后,在后台取到的CheckBox的值总是为false.最 ...

  6. 获取Repeater控件中的每一项数据

    var items = rptList.Items;//获取Repeater控件的所有项 foreach (RepeaterItem item in items)//遍历每一项内容 {   var t ...

  7. asp.net在用户控件中使用ClientScript

    在用户空间中调用ClientScript.RegisterClientScriptBlock方法 ClientScript的命名空间是System.Web.UI.Page,并且要实例化之后的Page才 ...

  8. Repeater控件中的三目运算

    <asp:Repeater ID="rptimg" runat="server">        <ItemTemplate>      ...

  9. Repeater控件中的LinkButton(转)

    LinkButton小用法: 1.在使用时可以通过CommandName和CommandArgument属性联合起来绑定并传值,如:CommandName="record"Comm ...

随机推荐

  1. SICP阅读笔记(一)

    2015-08-25   008   Foreword    QUOTE: I think that it's extraordinarily important that we in compute ...

  2. lucene.net 3.0.3、结合盘古分词进行搜索的小例子(转)

    lucene.net 3.0.3.结合盘古分词进行搜索的小例子(分页功能)   添加:2013-12-25 更新:2013-12-26 新增分页功能. 更新:2013-12-27 新增按分类查询功能, ...

  3. nginx配置文件(反向代理+集群+动静分离)

    1.nginx纯反向代理配置(nginx.conf): #user nobody;worker_processes 4;error_log logs/error.log info;pid logs/n ...

  4. 阿里云 Debian Linux 布署记录

    摘要: 主要安装了web环境,java+tomcat+mysql+nginx(暂没没用) 数据盘挂载在/data下,项目,索引都放/data目录下 java,tomcat,mysql程序都在/root ...

  5. java一点东西(3)

    运算符的优先级:()优先级最高 ! ++ -- 单目运算符 * / % + - > < <= >= == != && || 赋值符号 面向对象设计步骤:1.发现 ...

  6. 内存管理pbuf.h头文件源码解析——LwIP学习

    声明:个人所写所有博客均为自己在学习中的记录与感想,或为在学习中总结他人学习成果,但因本人才疏学浅,如果大家在阅读过程中发现错误,欢迎大家指正. LwIP的内核(core文件夹)文件中pbuf.c是包 ...

  7. (转)ubuntu下如何查看和设置分辨率

    转载请注明出处: http://www.cnblogs.com/darkknightzh/p/5681159.html 原网址: http://www.2cto.com/os/201303/19397 ...

  8. jQuery模糊选择

    属性字头选择器(Attribute Contains Prefix Selector) jQuery 属性字头选择器的使用格式是 jQuery(‘[attribute|=value]‘) ,例如 jQ ...

  9. PAT 1059. Prime Factors (25) 质因子分解

    题目链接 http://www.patest.cn/contests/pat-a-practise/1059 Given any positive integer N, you are suppose ...

  10. The number of divisors(约数) about Humble Numbers

    The number of divisors(约数) about Humble Numbers Time Limit: 2000/1000 MS (Java/Others)    Memory Lim ...