Set/Get checkbox value in Gridview

Hi all,

Hopefully a quick one, I have a normal Gridview with normal text columns but with one holding a checkbox for an "attended" field.  

What I'm after is that when this checkbox is ticked, on CheckedChanged event I want to update the database to say the course has been attended if the Checkbox is checked.

I can access the CheckedChanged event fine from within the Gridview, but I would like the checkbox to hold the ID of the course, so I can then automatically use a "Update tbl where ID = CHECKBOXVALUE".

I can only set the bound ID to either the Text or Checked parts of the Checkbox though, so the value is appearing alongside the Checkbox in the Gridview, which I don't want to be visable, is there a way to attach the value so I can use it but no have it display next to the checkbox?

Cheers
LVL 1
MiddlesbroughPCTAsked:
Who is Participating?
 
Oliver AmayaConnect With a Mentor EntrepeneurCommented:
Hi, what I usually do is have a label control along side it, assigned with the ID I need, and set it as not visible, if you can determined in which the checkbox is situated you can use FindControl to get the label.
0
 
Oliver AmayaEntrepeneurCommented:
Meant to say in which row of the GridView the checkbox is situated.
0
 
lonekawboyConnect With a Mentor Commented:
Use the DataKeys variable from the GridView to hold the key pieces of data for the grid. Then on events you can pull the values once you have the RowIndex for the GridViewRow i.e. gvResult.DataKeys[ gvrRow.RowIndex ][ "ID" ].
0
 
MiddlesbroughPCTAuthor Commented:
Both answers apply so split points, thanks for answering.
0
All Courses

From novice to tech pro — start learning today.