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 6154921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:20:35+00:00 2026-05-23T20:20:35+00:00

So I have this checkbox inside a gridview, and it is working properly for

  • 0

So I have this checkbox inside a gridview, and it is working properly for the most part. However, I am trying to implement column-sorting to the grid, and it is causing an issue with the checkbox. When I do my initial fetch from the database, it populates the checkboxes properly, but when I click on a column to sort by it, all of my checkboxes get cleared out.

It seems that this is a problem with the Databind being done by the gridview, but I’m not sure what I’m doing wrong. My research into the issue makes me feel like I have it right, but I don’t know for sure (legacy code: I hate it).

<asp:GridView ID="UserListGrid" runat="server"
    OnSorting="UserListGrid_Sort" AllowSorting = "True" AutoGenerateColumns="False"  
    AllowPaging="True" PageSize="25" OnRowDataBound="UserListGrid_RowDataBound" 
    OnPageIndexChanging="UserListGrid_PageIndexChanging">

.
.
.

    <ItemTemplate>
       <asp:CheckBox ID="ActiveCheck" runat="server" SortExpression="ActiveCheck"/>                                                   
    </ItemTemplate>

.
.
.

protected void UserListGrid_Sort(object sender, GridViewSortEventArgs e)
{
        // ViewState["CurTab"] = 0;
        DataTable Data = myData.GetSessionRoster(TeamID);
        DataView UserListView = new DataView(Data);
        ViewState["SortDirection"] = myData.ConvertSortDirectionToSql(ViewState["SortDirection"] == null ? "" : ViewState["SortDirection"].ToString());
        UserListView.Sort = e.SortExpression + " " + ViewState["SortDirection"];
        UserListGrid.DataSource = UserListView;
        UserListGrid.DataBind();
}

Is there anything obviously wrong with my sorting? I can provide more code if needed.

As requested, here is UserListGrid_RowDataBound

protected void UserListGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType != DataControlRowType.DataRow)
    {
        return;
    }
    // See which users are active
    CheckBox ActiveCheck = (CheckBox)e.Row.Cells[1].FindControl("ActiveCheck");
    if (ActiveCheck != null)
    {
        ActiveCheck.Enabled = true;
        if (e.Row.Cells[11].Text.Equals("1") && !Page.IsPostBack)
        {
            ActiveCheck.Checked = true;
            ActiveCheck.DataBind();
        }
    }
}
  • 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-05-23T20:20:35+00:00Added an answer on May 23, 2026 at 8:20 pm

    It looks like you’re populating checkboxes not from the data base, but corresponding to the contents of your cell 11 (whatever it is).
    I appeal to this code line:

    if (e.Row.Cells[11].Text.Equals("1") && !Page.IsPostBack)
    

    While sorting you rebind your gridview, but you restrict populating and rebinding of your checkboxes on postback. This could be a reason for checkboxes loosing values.

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

Sidebar

Related Questions

I have a checkbox inside a gridview like this <asp:GridView ID=GridView1 runat=server BorderColor=Blue BorderWidth=1px
I have this checkBox in my view inside a form: <g:checkBox name=myCheckbox value=${false} />
I have a gridview with checkbox inside asp:TemplateField . I wish to select multiple
I have this js code: $(#startSearch).live(click, function(event) { $(input:checkbox[name='searchId']:checked).each(function() { var searchId = $(this).val();
I have this case <WrapPanel> <CheckBox>Really long name</CheckBox> <CheckBox>Short</CheckBox> <CheckBox>Longer again</CheckBox> <CheckBox>Foo</CheckBox> <Slider MinWidth=200
I have read this. Jquery checkbox <input type=checkbox name=checkGroup id=all> <input type=checkbox name=checkGroup id=one
I have a web page that consists of a checkbox (parent) and on this
I have a .NET application that contains a checkbox (System.Windows.Forms.Checkbox). This component (WindowsForms10.BUTTON.app.0.378734a1) is
I have a Listbox, that has a Checkbox as part of the item template.
I have GridView with CheckBox in it's header and another one in each row:

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.