Click here to Skip to main content
15,899,679 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hoew to check checkboxes in gridview

C#
if (chidgridVal.rows.length > 0) {
                  //                         alert("hii222");
                  for (i = 0; i <= chidgridVal.rows.length; i++) {
                      alert(i + 2);

                      document.getElementById('ctl00_MainContent_gvParentGrid_ctl02_gvChildGrid_ctl0' + (i + 6).toString() + '_ui_access').checked == true;
                      var chkUIACCESS = document.getElementById('ctl00_MainContent_gvParentGrid_ctl02_gvChildGrid_ctl0' + (i + 2).toString() + '_ui_access').checked
                      alert(chkUIACCESS);
                      if (chkUIACCESS == true) {
                          alert("chldchk");
                      }
                      else { alert("clhdunchk"); }
                  }
              }


i havewritten below code so that chkboxes will get chked but not getting chkd
document.getElementById('ctl00_MainContent_gvParentGrid_ctl02_gvChildGrid_ctl0' + (i + 6).toString() + '_ui_access').checked == true;
Posted
Updated 5-Aug-13 1:05am
v4

1 solution

document.getElementById('ctl00_MainContent_gvParentGrid_ctl02_gvChildGrid_ctl0' + (i + 6).toString() + '_ui_access').checked == true; 


== operator is an equality operator which returns a boolean value - true if the values of its operands are equal, false otherwise.

Since you need to check the checkbox here, you need an assignment operator (=). So replace your code with document.getElementById('ctl00_MainContent_gvParentGrid_ctl02_gvChildGrid_ctl0' + (i + 6).toString() + '_ui_access').checked = true; and it should work

For more about the operators, read the MSDN reference: C# Operators[^]
 
Share this answer
 
Comments
Member 9410081 5-Aug-13 7:09am    
Thanks
Ankur\m/ 5-Aug-13 7:55am    
Downvoter - reason please?

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