如何检查所有,取消选中所有,检查一些选项? [英] How to check all, uncheck all, check some options?

查看:77
本文介绍了如何检查所有,取消选中所有,检查一些选项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<pre lang="c#">
<asp:CheckBoxList ID="Student" class="checkS" align="left" runat="server" 

              onselectedindexchanged="Student_SelectedIndexChanged" AutoPostBack="true" >
                <asp:ListItem Text="Insert"   Value="Insert" ></asp:ListItem>                
                <asp:ListItem Text="Update" Value="Update"></asp:ListItem>
                <asp:ListItem Text="View"   Value="View"></asp:ListItem>
                <asp:ListItem Text="All"    Value="Delete"></asp:ListItem>
            </asp:CheckBoxList>










protected void Student_SelectedIndexChanged(object sender, EventArgs e)
  {

      foreach (ListItem li in Student.Items)
      {
          // li.Selected = true;
          if (li.Text == "All" && li.Selected == true)
          {
              foreach (ListItem li1 in Student.Items)
              {
                  li1.Selected = true;
              }
          }

          if ((li.Text == "Insert" && li.Selected == true)|| (li.Text == "Update" && li.Selected == true))
          {
              Student.Items.FindByText("View").Selected = true;

          }

      }

  }





我尝试过:



1)如果我们检查所有==>选中所有复选框

2)取消选中所有==>所有未选中

3)如果选择插入/更新视图也应选择默认视图以进行插入和更新



What I have tried:

1)If we check all==> all checkboxes are selected
2)uncheck all==>all are unchecked
3)if select insert/update view also should select by default view for insert and update

推荐答案

我建​​议使用jquery来选择和取消选中复选框,因为1.它不会导致回发,2。你可以使用checkboxList类-checks-选择全部/取消全选。

示例:
I suggest use of jquery to do selecting and unselecting of the checkboxes because 1. It will not result to a postback, 2. You can use checkboxList class -checks- to select all / unselect all.
Example:


(input [type ='checkbox'])。change(function() {

if(checkboxname ==checkall){

if(this.checked){
("input[type='checkbox']").change(function () {
if (checkboxname=="checkall") {
if (this.checked) {


( .checks)。prop(checked,true);

}

else {
(".checks").prop("checked", true);
}
else {


这篇关于如何检查所有,取消选中所有,检查一些选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆