Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. Firing an gridview event from a checkbox control inside a GridView

Firing an gridview event from a checkbox control inside a GridView

Scheduled Pinned Locked Moved ASP.NET
sysadmintutorialquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    LancashireLad
    wrote on last edited by
    #1

    This seems like a ridicously easy thing to do but I'm stumped... I have a databound checkbox that I am displaying in a Gridview (template) column. I want to be able to fire a server event whenever a user clicks on a checkbox. Since the gridview control doesn't fire an event when the user clicks on the checkbox, my app can't figure out which row was clicked. The OnCheckedChanged event does work but I can't find a way to pass the key field to the event to identify which checkbox was changed. Any clues on how how to get a checkbox in a GridView control to fire a gridview event when a checkbox is updated by the user? Thanks in advance!

    P 1 Reply Last reply
    0
    • L LancashireLad

      This seems like a ridicously easy thing to do but I'm stumped... I have a databound checkbox that I am displaying in a Gridview (template) column. I want to be able to fire a server event whenever a user clicks on a checkbox. Since the gridview control doesn't fire an event when the user clicks on the checkbox, my app can't figure out which row was clicked. The OnCheckedChanged event does work but I can't find a way to pass the key field to the event to identify which checkbox was changed. Any clues on how how to get a checkbox in a GridView control to fire a gridview event when a checkbox is updated by the user? Thanks in advance!

      P Offline
      P Offline
      pmarfleet
      wrote on last edited by
      #2

      The CheckBox control has an AutoPostBack[^] property. Set it to true to get the control to initiate a postback when it is clicked. Wire all your checkboxes to the same event handler. When a postback occurs, the sender argument of your event handler will contain a reference to the control that initiated the postback.

      Paul Marfleet "No, his mind is not for rent To any God or government" Tom Sawyer - Rush

      L 1 Reply Last reply
      0
      • P pmarfleet

        The CheckBox control has an AutoPostBack[^] property. Set it to true to get the control to initiate a postback when it is clicked. Wire all your checkboxes to the same event handler. When a postback occurs, the sender argument of your event handler will contain a reference to the control that initiated the postback.

        Paul Marfleet "No, his mind is not for rent To any God or government" Tom Sawyer - Rush

        L Offline
        L Offline
        LancashireLad
        wrote on last edited by
        #3

        Thanks for responding. I don't need the value of the checkbox (in the sender object). Instead, I need the value of the key field for the row clicked (which is in a hidden field in the GridView control). Thanks

        P 1 Reply Last reply
        0
        • L LancashireLad

          Thanks for responding. I don't need the value of the checkbox (in the sender object). Instead, I need the value of the key field for the row clicked (which is in a hidden field in the GridView control). Thanks

          P Offline
          P Offline
          postmaster programmingknowledge com
          wrote on last edited by
          #4

          On Checkbox_Checkchanged event you can get the handle of the current Gridview row using Sender object, eg. this.Parent.NamingContainer which is gridviewRow Postmaster http://www.programmingknowledge.com/[^]

          L 1 Reply Last reply
          0
          • P postmaster programmingknowledge com

            On Checkbox_Checkchanged event you can get the handle of the current Gridview row using Sender object, eg. this.Parent.NamingContainer which is gridviewRow Postmaster http://www.programmingknowledge.com/[^]

            L Offline
            L Offline
            LancashireLad
            wrote on last edited by
            #5

            Thanks for the help. Got it!

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups