Click here to Skip to main content
15,912,665 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
JavaScript
<script type="text/javascript">
function CheckBoxCheck(rb) {
            debugger;
            var gv = document.getElementById("<%=GridView1.ClientID%>");
            var chk = gv.getElementsByTagName("input"); ;
            var row = rb.parentNode.parentNode;
            for (var i = 0; i < chk.length; i++) {
                if (chk[i].type == "checkbox") {
                    if (chk[i].checked && chk[i] != rb) {
                        chk[i].checked = false;
                        break;
                    }
                }
            }
        }

C#
<asp:GridView ID="GridView1" runat="server"> 
<columns>
 <asp:TemplateField HeaderText="check">
<edititemtemplate>
<asp:CheckBox ID="CheckBox1" runat="server" />
</edititemtemplate>
  <itemtemplate>
<asp:CheckBox ID="CheckBox1" runat="server" OnCheckedChanged="CheckBoxCheck(this);" />
</itemtemplate>

</columns>

ERRORR:expected ')'
where i have done mistake
can any one help me
thanks in advance......
Posted
Updated 30-Nov-14 20:28pm
v3
Comments
Kornfeld Eliyahu Peter 1-Dec-14 1:39am    
Why checkbox? If you can select only one at a time you should use radio-button! It has that ability built in...
Encap 1-Dec-14 1:59am    
why to use radio button?.. i think check box can also check only one at a time is it true??..
Praveen Kumar Upadhyay 1-Dec-14 3:25am    
I think the error is coming from some other block of code.

Problem, which I can see...


CheckBox.OnCheckedChanged Method[^] is a Server Side Event.

For client side, you can use onchange.
 
Share this answer
 
Comments
King Fisher 1-Dec-14 5:23am    
you are Right :)
Thanks King. :)
it is related to syntax error in your java script. Please remove one semicolon from below line.

Please check at below line:
var chk = gv.getElementsByTagName("input"); ;
 
Share this answer
 
Comments
Encap 1-Dec-14 1:56am    
i removed the semi colon then also it shows same error expected ')'
Can you check your function again?
Where is "rb" variable defined?

C#
var row = rb.parentNode.parentNode;
 
Share this answer
 
Comments
rizwan muhammed khan gouri 1-Dec-14 4:30am    
it passes here CheckBoxCheck(rb)
Do the comparison on basis of checkbox id rather then comparing the complete checkbox object.
 
Share this answer
 

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