Saturday, 27 September 2014

Select/Unselect All inside griview with modal popup using javascript with Color selected rows


//Gridview

<asp:TemplateField >
 <ItemTemplate>
 <asp:CheckBox runat="server" ID="Chk_allCh" />
  </ItemTemplate>
 <HeaderTemplate>
 <asp:CheckBox runat="server" ID="Chk_all" onclick="checkAllRow(this);" />
</HeaderTemplate>
</asp:TemplateField>


//Script

function checkAllRow(objRef) {
       var GridView = objRef.parentNode.parentNode.parentNode.parentNode.parentNode;
       var inputList = GridView.getElementsByTagName("input");
       for (var i = 0; i < inputList.length; i++) {
           //Get the Cell To find out ColumnIndex
           var row = inputList[i].parentNode.parentNode;
           if (inputList[i].type == "checkbox" && objRef!= inputList[i]) {
              if (objRef.checked) {
       //If the header checkbox is checked//check all checkboxes//and highlight all rows
                 row.style.backgroundColor = "#5CADFF";
                 inputList[i].checked = true;
                }
           else {
       //If the header checkbox is checked//uncheck all checkboxes//and change rowcolor back to original
               if (row.rowIndex % 2 == 0) {
                //Alternating Row Color
                  row.style.backgroundColor = "#AED6FF";
                  }
                  else {
                   row.style.backgroundColor = "white";
                     }
                      inputList[i].checked = false;
                           }
                       }
                   }

               }

No comments:

Post a Comment

How to highlight selected text in notepad++

  –> To highlight a block of code in Notepad++, please do the following steps step-1  :- Select the required text. step-2  :- Right click...