C # GridView CheckBox implements a single selection

Source: Internet
Author: User

About the GridView Add a checkbox, how to use JS to add a radio event, in fact, the code is not very difficult, but the original also checked the information, only for record, master bypass ha. The format in ASPX is as follows:

<div>    <table>        <td>< Asp:gridview id= "Humidnmgridview" >             <Columns>                <asp:TemplateField>                       <HeaderTemplate>                           <asp:image id= "oimg"  runat= "Server"  imageurl= ". /.. /images/icon_sure.gif ">                          </asp:image> //icons can be ignored                         

The following is javascript:

var clickcount = 0; //Judging the same checkbox continuous clicks          var precheckboxid =  "";  //record click on the checkbox id        / /gridviewid  for the Id        function singlecheck of the incoming GridView ( Divgridview, selectcheckbox)  {             //console.info (Divgridview);             // Console.info (Selectcheckbox);             // Determine whether consecutive clicks of the same checkbox            if  ( Precheckboxid == selectcheckbox)  {                 ClickCount += 1;             } else  {                precheckboxid  = SelectCheckBox.id;                 ClickCount = 0;             }            //find the divid  containing the checkbox            var GridViewList =  document.getElementById (Divgridview);             / /Get more input            var objs = in divID  gridviewlist.getelementsbytagname ("input");             for  (var i = 0; i < objs.length; i++)  {                 if  (Objs[i].type.tolowercase ()  ==  " CheckBox ")  {                     objs[i].checked = false;                 }                 var SelectCheckBoxId = SelectCheckBox.id;                 // CheckBox is selected if the number of clicked checkboxes is odd, but not selected                  if  (clickcount % 2 != 1)  {                      document.getElementById (SELECTCHECKBOXID) .checked = true;                } else  {                     document.getelementbyid (SELECTCHECKBOXID) .checked = false;                 }             }        }



C # GridView CheckBox implements a single selection

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.