Solved

Set/Get checkbox value in Gridview

Posted on 2007-11-22
4
6,933 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:
joex911 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:joex911
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This video discusses moving either the default database or any database to a new volume.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now