Click here to Skip to main content
15,912,932 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 !
Posted

You can use the following code :

JavaScript
//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;
     }
}


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

Hope this helps.
 
Share this answer
 
Comments
Taresh Uppal 30-May-12 0:59am    
I am not getting the logic means do i have to use this with my existing javascript code ? and how it will select all the checkboxes on all the pages of gv ?
when you click on check box and select all check box selected and send mail then you will save this data in database and keep them on all pages
when binding to grid
 
Share this answer
 
Comments
Taresh Uppal 30-May-12 1:33am    
I am not getting you ?? means wats the logic ?
When you select the header check box, it will only select the rows that are available on that page.... (as i am assuming that all the contacts are not loaded, as you are paging.). So no way to select all in current way.

What i can say that...you may need to change the current process. Can follow either one of them....

1> Better use a button labeled "Send mail to all" and call a method to get all from db and send email.

OR

2> Load all contacts on page. And show only the paged contacts. This way i think your code will work.
 
Share this answer
 
Comments
Taresh Uppal 30-May-12 2:10am    
I have seen people solving this issue some of them did it on row data bound event of Grid view and paging soem with javascript.. Only I am not able to solve it at the moment..So kindly help..:(

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900