locked
alternative check box checked status - Validation RRS feed

  • Question

  • Hi guys,

    I have some doubt while implementing 2 check box in gridview item templeate please suggest some good solution.

    Gridview Design :

    <asp:templeate >

    <itemtempleate>

    <asp:checkbox id="checkbox1" runat="server"/>

    <asp:checkbox id="checkbox2" runat="server"/>

    </itemtempleate>

    </asp:templeate>

    Requirement :

    I have 2 check box in gridview like name checkbox1 & checkbox 2 in itemtempleate while checking checkbox1 status would be checked, but if checking the check box 2 checked automatically check box 1 also.

    please some good solution 

    Thanks for advance

    


    Ranganathan.Palanisamy

    • Moved by Mike Dos Zhang Wednesday, July 18, 2012 9:55 AM (From:JScript for the .NET Framework)
    Wednesday, July 4, 2012 8:07 PM

Answers

  • Ran,
    See the code below helps you:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <script language="javascript" type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.2.min.js"></script>
    <script>
    function disable(ds, at){
    	$('#' + ds).removeAttr('checked');
    	$(at).attr('checked', 'checked');
    }
    </script>
    </head>
    
    <body>
    <input name="checkbox1" id="checkbox1" type="checkbox" value="1" onclick="disable('checkbox2', this);" />
    <input name="checkbox2" id="checkbox2" type="checkbox" value="1" onclick="disable('checkbox1', this);" />
    </body>
    </html>
    
    In <asp:checkbox> use OnClientClick instead of OnClick to activate the checkbox.

    Hope this helps ... good luck!


    Não esqueça de marcar como útil uma resposta que te ajude.
    "A diversão é a alma do negócio"

    Friday, July 6, 2012 1:43 PM

All replies

  • Hi Ranganathan.Palanisamy ,

    Do you want to set only one checkbox to be checked ? If so , you can control  this by code ,like 
     

    protected void CheckBox1_CheckedChanged(object sender, EventArgs e){  }
    protected void CheckBox2_CheckedChanged(object sender, EventArgs e) {   }

    However , I would like to recommend  you to use radiobutton which can realize your requirement  easily .

    BTW , Please use the ASP.NET forums for ASP.NET related questions: http://forums.asp.net/

    Regards ,


    Lisa Zhu [MSFT]
    MSDN Community Support | Feedback to us

    Friday, July 6, 2012 6:24 AM
  • Ran,
    See the code below helps you:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <script language="javascript" type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.2.min.js"></script>
    <script>
    function disable(ds, at){
    	$('#' + ds).removeAttr('checked');
    	$(at).attr('checked', 'checked');
    }
    </script>
    </head>
    
    <body>
    <input name="checkbox1" id="checkbox1" type="checkbox" value="1" onclick="disable('checkbox2', this);" />
    <input name="checkbox2" id="checkbox2" type="checkbox" value="1" onclick="disable('checkbox1', this);" />
    </body>
    </html>
    
    In <asp:checkbox> use OnClientClick instead of OnClick to activate the checkbox.

    Hope this helps ... good luck!


    Não esqueça de marcar como útil uma resposta que te ajude.
    "A diversão é a alma do negócio"

    Friday, July 6, 2012 1:43 PM