前台:(每个脚本函数其中有一个GridView1的ID需要更改)
<body>
<script type="text/javascript" language="javascript">
 function selectAll(object)
  { 
   
    table = document.all.GridView1;
    var chk = table.getElementsByTagName("input");
    for(var i=0;i<chk.length;i++)
    {
     chk[i].checked = object.checked;
    }
  }
  function UnselectAll()
        {
            table = document.all.GridView1;
      var chk = table.getElementsByTagName("input");
   for(var i=0;i<chk.length;i++)
   {
     if(chk[i].id!="chkAll")
     {
    if(chk[i].checked)
    {
       chk[i].checked=!chk[i].checked;
    }
    else
    {
         chk[i].checked=true;
    }
     }
   }
  }

        function  checkselectAll()
        {
           
            var num=0;//未选中
            table = document.all.GridView1;
      var chk = table.getElementsByTagName("input");
   for(var i=0;i<chk.length;i++)
   {
     if(!chk[i].checked)
     {
       num++;
     }
     if(num>0)
     {
        for(var j=0;j<chk.length;j++)
          {
             if(chk[j].id=="chkAll"&&chk[j].checked==true)
             {
             chk[j].checked=false;
          }
       }
     }
   
   
   }
   
  }
  function checkselect()
  {
     var count=0;//选中
     table = document.all.GridView1;
      var chk = table.getElementsByTagName("input");
   for(var i=0;i<chk.length;i++)
   {
     if(chk[i].checked)
     {
       count++;
     }
     if(count==5)
     {
     for(var k=0;k<chk.length;k++)
     {
      if(chk[k].id=="chkAll"&&chk[k].checked==false)
      {
       chk[k].checked=true;
      }
      break;
     }
     }
    }
  }
</script>

 

<asp:TemplateField>
                    <HeaderTemplate>
                       <input >
           <asp:LinkButton >删除</asp:LinkButton>

                    </HeaderTemplate>
                    <ItemTemplate>
                        <input />

                    </ItemTemplate>
</asp:TemplateField>

 


<input >反选(随便放在哪里)

 

后台:


protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
       //if(e.CommandName=="select")
       //{
       //    Response.Redirect("index.aspx");
       //}
        #region 删除所有选中记录

        if (e.CommandName == "delet")
        {
            System.Web.UI.HtmlControls.HtmlInputCheckBox check;

            foreach (GridViewRow dgi in GridView1.Rows)
            {
                check = ((System.Web.UI.HtmlControls.HtmlInputCheckBox)dgi.Cells[12].FindControl("chk"));
                if (check != null)
                {
                    if (check.Checked)
                    {
                        Response.Write("选中的值主键值为:" + check.Value + "<br>");
                    }
                }
            }

        }

        #endregion
       
    }

相关文章:

  • 2022-12-23
  • 2021-09-17
  • 2021-08-12
  • 2021-11-10
  • 2022-01-14
  • 2021-09-10
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-19
  • 2021-12-04
  • 2021-05-31
  • 2022-12-23
相关资源
相似解决方案