Solved

Set/Get checkbox value in Gridview

Posted on 2007-11-22
4
6,951 Views
Last Modified: 2010-04-21
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
0
Comment
Question by:MiddlesbroughPCT
  • 2
4 Comments
 
LVL 10

Accepted Solution

by:
Oliver Amaya earned 65 total points
ID: 20336003
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
 
LVL 10

Expert Comment

by:Oliver Amaya
ID: 20336009
Meant to say in which row of the GridView the checkbox is situated.
0
 

Assisted Solution

by:lonekawboy
lonekawboy earned 60 total points
ID: 20336954
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
 
LVL 1

Author Closing Comment

by:MiddlesbroughPCT
ID: 31410583
Both answers apply so split points, thanks for answering.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question