js之Repeater-实现全选

时间:2022-06-01 12:45:15

 function CheckAll()
  {
  for(var i = 0; i < document.form1.commentid.length; i++)
  {
  if(document.form1.commentid[i].checked == false)
  document.form1.commentid[i].checked = true;
  else
  document.form1.commentid[i].checked = false;
  }
  } 
<input type="button" name="checkAll" value="选中本页所有项" onclick="CheckAll();" class="inputbut
1.放在Repeater控件中使用:

<asp:Repeater ID="rptMsgList" runat="server">
<ItemTemplate>
"/><dt class="dt">
<input type="checkbox" name="commentid" id="commentid" value="<%#Eval("id") %>" />
<img src="../images/pic/icon.jpg" alt="" />

</dt>
<dt class="dd">
<%#NT.Common.NTString.toHtml(Eval("msgcontent").ToString())%>
</dt>
</ItemTemplate>
</asp:Repeater>

2.后台cs获取:

  protected void btnPass_Click(object sender, EventArgs e)
  {
  bool brt = false;
  string[] commentids = Request["commentid"].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
  foreach (string id in commentids)
  {
  brt=comment.CommentCheck(Convert.ToInt32(id));
  }

  DisPlayCommentList();
  }