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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:42:30+00:00 2026-05-13T16:42:30+00:00

I have a custom gridview control that extends the standard asp.net gridview control. The

  • 0

I have a custom gridview control that extends the standard asp.net gridview control. The first column of the gridview is composed of dynamically created checkboxfields.
I have assigned an event to the CheckChanged event of the checkboxes during the OnRowDataBound event, but the checkboxes do not even fire the event. I have their autopostback property set to true, and they ARE doing a postback, but it doesn’t even attempt to fire the OnCheckChanged event.
Here is my code:
The OnRowDataBound event of the gridview:

protected override void OnRowDataBound(GridViewRowEventArgs e)
        {
            base.OnRowDataBound(e);
            if (e.Row.RowType == DataControlRowType.DataRow)
            {

                CheckBox chkSelect = (CheckBox)e.Row.Cells[CheckBoxColumnIndex].FindControl(InputCheckBoxField.CheckBoxID);
                if (chkSelect != null)
                {
                    Guid selectedValue = new Guid(DataKeys[e.Row.RowIndex].Value.ToString());
                    chkSelect.Checked = SelectedValues.Contains(selectedValue);
                    chkSelect.CheckedChanged += new EventHandler(CheckChanged_click);
                }
            }
        }

The CheckChanged event:

protected void CheckChanged_click(object sender, EventArgs e)
        {
            CheckBox chkSelect = (CheckBox)sender;
            GridViewRow gvr = (GridViewRow)chkSelect.Parent.Parent;
            Guid selectedValue = new Guid(DataKeys[gvr.RowIndex].Value.ToString());
            if (chkSelect.Checked && !this.SelectedValues.Contains(selectedValue))
            {
                this.SelectedValues.Add(selectedValue);
            }
            else if (!chkSelect.Checked && this.SelectedValues.Contains(selectedValue))
            {
                this.SelectedValues.Remove(selectedValue);
            }
            DataBind();
        }

One other thing. This USED to work, but as I was developing the control, I discovered that it was databinding multiple times on page load. I went through and began trimming down the databinds so that it would only bind once during page load. This is a side effect of doing that.

I’ve tried moving the CheckChanged assignment into OnInit, and into OnRowCreated as well, but it still doesn’t fire.

  • 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-13T16:42:30+00:00Added an answer on May 13, 2026 at 4:42 pm

    As for your event:

     CheckBox chkSelect = (CheckBox)e.Row.Cells[CheckBoxColumnIndex].FindControl(InputCheckBoxField.CheckBoxID);
          if (chkSelect != null)
          {
               Guid selectedValue = new Guid(DataKeys[e.Row.RowIndex].Value.ToString());
               chkSelect.Checked = SelectedValues.Contains(selectedValue);
               chkSelect.CheckedChanged += new EventHandler(CheckChanged_click);
          }
    

    It looks like you are publishing the event ‘after’ you change the check state. Try:

     CheckBox chkSelect = (CheckBox)e.Row.Cells[CheckBoxColumnIndex].FindControl(InputCheckBoxField.CheckBoxID);
    
          if (chkSelect != null)
          {
                chkSelect.CheckedChanged += new EventHandler(CheckChanged_click);
                Guid selectedValue = new Guid(DataKeys[e.Row.RowIndex].Value.ToString());
                chkSelect.Checked = SelectedValues.Contains(selectedValue);
          }
    
    // if your done with chkSelect
    chkSelect.CheckedChanged -= CheckChanged_click;
    

    If your event still isn’t firing, you will have to step through to see what the SelectedValue.Contains(selectedValue) is returning.

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

Sidebar

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.