Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


Checked checkboxes not showing checked in gridview

Checked checkboxes not showing checked in gridview

Checked checkboxes not showing checked in gridview

I have 3 reports where I have a checkbox column as the first column which a checkbox in the header as my select/unselect all checkbox. I use jquery to select/unselect all. Two of the reports do this select/unselect all correctly all of the time. One of the reports only do it correctly once.

The jquery code and checkboxes in the gridview are the same. Which makes sense since the behavior is correct the first time.

What is happening is that the checkboxes are getting set correctly but the browsers (ie, chrome and firefox) all do not show the checkboxes as selected in the rows (but the one in the header does). I can see this in the Developer tools. All the checkboxes show as checked when the header checkbox is selected and as unselected when the header checkbox is unselected.

I can manually, check the boxes in some of the rows and when unselected all, they disappear but when I then press the select all checkbox they still show on the screen as unselected (but as selected in the developer tools).

Any idea why that is the case?

It almost seems like the grid is getting rebound but that isn't the case.



RE: Checked checkboxes not showing checked in gridview

It's hard to say. I would first check all of your JQuery code to make sure there isn't some code doing something you don't want, like changing a visible or display property.

Post your jquery code and gridview markup

RE: Checked checkboxes not showing checked in gridview

Unfortunately, I can't. It is really a large sheet.

The jquery code is:


$(".selectall").change(function () {
            var checkBoxSelectorAll = '#<%=gvSelectionGrid.ClientID%> input[id*="chkSelectAll"]:checkbox';
            var checkBoxSelectorRows = '#<%=gvSelectionGrid.ClientID%> input[id*="chkSelected"]:checkbox';

            $(checkBoxSelectorRows).attr('checked', $(checkBoxSelectorAll).is(":checked"));

The code in the GridView is:


<asp:TemplateField HeaderText="Select" HeaderStyle-ForeColor="white" HeaderStyle-Width="25px">
      <asp:CheckBox ID="chkSelectAll" runat="server" CssClass="selectall"  />
      <asp:CheckBox ID="chkSelected" runat="server" style="margin-right: 2px" CssClass="selectrow" />
      <asp:HiddenField ID="hdnCAParticipantID" runat="server" Value='<%# Bind("CAParticipantID") %>' />
   <HeaderStyle ForeColor="White" Width="25px" />

I found out how to make it work.

Everything above is the same but I add an AutoPostback = "true" in the first checkbox (the one in the Header) and it works fine. The code behind just goes to Page_Load but doesn't do anything (no rebinding). But it works.

It's like the checkboxes will not redisplay the "check" in the checkbox if it was already done once (even though it does add the checked="checked to the checkbox each time the select all checkbox is checked).

Same with all browsers. It's like you need to do a postback to reset the objects first.

RE: Checked checkboxes not showing checked in gridview

You should only need to bind once by putting your bind code in and If Not page.IsPostBack End If

If you are adding controls dynamically then you will need to add them each time. It's really hard to know and see what the issue is without seeing the code.
I know it is working, but I am assuming it is a side affect of posting the page again when you really don't need to.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close