本文介绍了如何在标题复选框的检查框上的网格视图中检查所有复选框,包括页面索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我有一个网格视图,其中有一个标题复选框,在该子复选框下面.当我选中标题复选框时,所有复选框均被选中,但仅在gv的现有页面上.当我移至下一页时,我看到未选中下一页的复选框.因此,如果万一我要通过选中电子邮件ID前面的复选框来实现向所有用户发送电子邮件的功能,那么我会遇到一个问题,即只有gv第一页上的用户才能收到电子邮件.它们中的其余部分不能仅仅因为未完全选中复选框而得到它.我在论坛上看到了很多示例,但对我没有用.你能建议点什么吗?这是我的Java脚本代码:

Hi,
I have a grid view in which I have taken a header check box and under that child check boxes. When I check header check box all check boxes get checked but on the existing page of the gv only. When i move to the next page I see that the check boxes of next pages are not checked. So if in case I am making a functionality in which i want to send emails to all users by checking the check boxes in front of there Email Ids i encounter a problem that only users existing on first page of gv receive the Emails. Rest of them don''t get it just because check boxes are not selected completely. I have seen a lot of examples on forums but nothing was useful to me. Can u suggest something ? Here is my Java scrip code :

<pre lang="Javascript">
window.onload = function()
{
   //Get total no. of CheckBoxes in side the GridView.
   TotalChkBx = parseInt();

   //Get total no. of checked CheckBoxes in side the GridView.
   Counter = 0;
}

function HeaderClick(CheckBox)
{
   //Get target base & child control.
   var TargetBaseControl =
       document.getElementById(''<%= this.gvAllClients.ClientID %>'');
   var TargetChildControl = "chkEmail_Single";

   //Get all the control of the type INPUT in the base control.
   var Inputs = TargetBaseControl.getElementsByTagName("input");

   //Checked/Unchecked all the checkBoxes in side the GridView.
   for(var n = 0; n < Inputs.length; ++n)
      if(Inputs[n].type == ''checkbox'' &&
                Inputs[n].id.indexOf(TargetChildControl,0) >= 0)
         Inputs[n].checked = CheckBox.checked;

   //Reset Counter
   Counter = CheckBox.checked ? TotalChkBx : 0;
}

function ChildClick(CheckBox, HCheckBox)
{
   //get target control.
   var HeaderCheckBox = document.getElementById(HCheckBox);

   //Modifiy Counter;
   if(CheckBox.checked && Counter < TotalChkBx)
      Counter++;
   else if(Counter > 0)
      Counter--;

   //Change state of the header CheckBox.
   if(Counter < TotalChkBx)
      HeaderCheckBox.checked = false;
   else if(Counter == TotalChkBx)
      HeaderCheckBox.checked = true;
}



请帮忙!



Help please !

推荐答案


//Check all checkboxes in the grid.
function CheckAll(header,gridView)
{
    id = gridView.id;
    var rowCount = gridView.firstChild.childNodes.length;
    for(var i=2;i<rowCount+1;i++)
    {
        if(i<10)
            controlId = id+"_ctl0"+i;
        else
            controlId = id+"_ctl"+i;
        document.getElementById(controlId+'_chkPost').checked = header.checked;
     }
}



参数标题将是Grid Header列中的CheckBox,而gridView是您的Grid Object.

希望对您有帮助.



The parameters header will be the CheckBox in the Grid Header Column and gridView is your Grid Object.

Hope this helps.



这篇关于如何在标题复选框的检查框上的网格视图中检查所有复选框,包括页面索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 13:57