Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9241453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:22:29+00:00 2026-06-18T08:22:29+00:00

I have the following checkBox function in a gridView- <Columns> <asp:TemplateField> <ItemTemplate> <asp:CheckBox ID=chkRow

  • 0

I have the following checkBox function in a gridView-

<Columns>
    <asp:TemplateField>
     <ItemTemplate>
        <asp:CheckBox ID="chkRow" runat="server" OnCheckedChanged="CheckBoxPN_CheckedChanged" AutoPostBack="true" />
     </ItemTemplate>

Which creates a checkBox for every row created in the gridView.

My problem being that in the event-

protected void CheckBoxPN_CheckedChanged(Object sender, EventArgs e)
    {

        CheckBox chk = (CheckBox)sender;
        GridViewRow row = (GridViewRow)chk.NamingContainer;  

        int gID = System.Convert.ToInt16(row.Cells[1].Text);

        gridViewDataSource.SelectCommand = sqlCommand + gID;
    }

I am using this to retrieve values. How ever once a user checks a checkBox, then goes to check another one, the previous checkBox state is still checked.

How can I modify the code to uncheck the last checkBox when the new one is checked?

EDIT
@Neil Knight ‘s answer implements the correct functionality, however as I am using the checked_changed event, when the new checkBox is getting checked, this fires the event, and gets the correct answer. However when the previous checkBox gets unchecked, this again fires the event and gets the wrong answer. How can I stop the gID value getting replaced with the old answer?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T08:22:30+00:00Added an answer on June 18, 2026 at 8:22 am

    ASP.Net example:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    <title>checkboxes</title>
    <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
    <meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
    <meta content="JavaScript" name="vs_defaultClientScript">
    <meta content="http://schemas.microsoft.com/intellisense/ie5"
    name="vs_targetSchema">
    <script language="javascript">
    function SingleSelect(regex,current)
    {
    re = new RegExp(regex);
    
    for(i = 0; i < document.forms[0].elements.length; i++) {
    
    elm = document.forms[0].elements[i];
    
    if (elm.type == 'checkbox') {
    
    if (re.test(elm.name)) {
    
    elm.checked = false;
    
    }
    }
    }
    
    current.checked = true;
    
    }
    </script>
    </HEAD>
    <body>
    <form id="Form1" method="post" runat="server">
    <table width="100%" align="center">
    <tr>
    <td>
    <br/>aaaa<input type="checkbox" id="chkOne" name="chkOne"
    value="aaaa" checked onclick="SingleSelect('chk',this);" />
    <br/>bbbb<input type="checkbox" id="chkTwo" name="chkTwo"
    value="bbbb" onclick="SingleSelect('chk',this);" />
    <br/>cccc<input type="checkbox" id="chkThree" name="chkThree"
    value="cccc" onclick="SingleSelect('chk',this);" />
    <br/>dddd<input type="checkbox" id="chkFour" name="chkFour"
    value="dddd" onclick="SingleSelect('chk',this);" />
    <br/>eeee<input type="checkbox" id="chkFive" name="chkFive"
    value="eeee" onclick="SingleSelect('chk',this);" />
    </td>
    </tr>
    <tr>
    <td></td>
    </tr>
    <tr>
    <td></td>
    </tr>
    </table>
    </form>
    </body>
    </HTML>
    

    Taken from Stephen Cheng‘s answer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following ASP.NET server control checkboxes. <asp:checkbox id=chkMonS1 runat=server /> <asp:checkbox id=chkMonS2 runat=server
If I have the following CheckBoxList <asp:CheckBoxList ID=typeCheckBoxList runat=server RepeatDirection=Horizontal> <asp:ListItem Value=0>Student</asp:ListItem> <asp:ListItem Value=1>Parent</asp:ListItem>
Within a masterpage I have a standard DataGrid: <asp:DataGrid ID=dgMyGrid runat=server AutoGenerateColumns=false> <Columns> <asp:TemplateColumn>
I have the following code: function toggleChecked(status) { $(.checkbox).each( function() { $(this).attr(checked,status); }) }
i have the following code: $('#test') .append($.map(this.items, function (item, index) { return '<li><input type=checkbox
I have the following: $('input[name=myCheck]').change(function() { $('input:checkbox').removeAttr('checked'); }); How do I say: removeAttr('checked') for
I have the following function where a top checkbox controls other checkboxes in the
I have the following code: $(input:checkbox).click(function () { getIndex($(this).attr(value).index(this)); } The value of the
Currently Im have the following script which checks to see if a checkbox value
I have the following fiddle1 http://jsfiddle.net/y6tCt/35/ . I need to build the checkbox list

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.