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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:00:31+00:00 2026-05-17T23:00:31+00:00

I have a databound grid with a templated field column that is a checkbox.

  • 0

I have a databound grid with a templated field column that is a checkbox. When the user checks the checkbox, it will autopostback and update the row to indicate the box’s check state.

My first attempt was to simply use the OnCheckedChanged method, but when this gets called, I have no way to know which row the checkbox came from. Thus, I don’t know which row to update.

Can anyone suggest a method to determine which row the checkbox that fired the oncheckedchanged event came from? Or can you suggest a better way to achieve what I need to do?

I cannot bind the checkbox to the data column because I do not want the checkbox disabled in select mode, and do not wish to require the user to enter edit mode to change the value. I also need all rows to be editable. So, the best route seems to be in a templated column.

  • 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-17T23:00:31+00:00Added an answer on May 17, 2026 at 11:00 pm

    You could find the checked Checkbox by iterating over the rows.

    Protected Sub MyCheckBoxCheckedChanged(ByVal sender As Object, ByVal e As EventArgs)
        For Each row As GridViewRow In GridView1.Rows
            Dim cb As CheckBox = DirectCast(row.FindControl("MyCheckBoxID"), CheckBox)
            If sender Is cb AndAlso cb.Checked Then
                'Do something ...'
                Exit For
            End If
        Next
    End Sub
    

    This isn’t as inefficient as it looks like(when the Grid’s PageSize is not too high).

    You can also get the GridViewRow via Checkbox.Parent.Parent:

      Protected Sub MyCheckBoxCheckedChanged(ByVal sender As Object, ByVal e As EventArgs)
            Dim cb As CheckBox = DirectCast(sender, CheckBox)
            Dim row As GridViewRow = DirectCast(cb.Parent.Parent, GridViewRow)
            row.BackColor = DirectCast(IIf(cb.Checked, Color.Red, Color.White), Color)
      End Sub
    

    This is faster as option 1 but if you f.e. would nest the Checkbox in a Table in the future, this wouldn’t work anymore without adjustment.

    I would normally prefer option 1, because in an event-handler one millisecond more or less doesn’t matter.


    Update: getting the GridViewRow via NamingContainer is another(in my opinion the best) option:

    Dim row As GridViewRow = DirectCast(cb.NamingContainer, GridViewRow)
    

    This even still works when you nest the Checkbox inside other Controls like a Table.

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

Sidebar

Related Questions

i have a databound GridView in asp.net 2.0 with a row-selection link. When a
I have a DataBound GridView. However I have one column where the value comes
I have a databound list view and can set all the column widths manually
I have a ListView in WPF that is databound to a basic table that
I have a listbox that is databound to a Collection of objects. The listbox
I have an XML that needs to be databound to a WPF TreeView .
I have a grid view that is data bound to a dataset. In a
So I've got a databound grid view within a UpdatePanel. The idea is that
I have a databound ListBox with a DataTemplate setup. The DataTemplate contains a Grid
I have a TextBox that is databound to a TreeView. If the selected element

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.