Getting the Value of a Checkbox in the GridView Selected Row

K

Kirk

I have a GridView that displays several columns, one of which is a
checkbox field. This is populated at runtime from a SqlDataSource and
is not enabled (the user can't change it's value). I have turned on
the "Enable Selection" option, and I know I can identify what is the
currently selected row.

How can I get the value [True/False] of the checkbox in the selected
row? For columns that are just text, this works:


System.Diagnostics.Trace.WriteLine(Me.GridView1.SelectedRow.Cells(3).Text)


...but it does not work on a column that is a checkbox (returns
nothing
since there is no text in that column). I have tried to use the
Ctype
method to cast the column as a checkbox, but I can't get that to work
either.


I realize that I am missing something stupid, and I would appreciate
a
tip or suggestion.
Thank you!
 
K

Kirk

David,

Thanks for your quick reply! Unfortunately, I must not be using your
example correctly.

I modified the code to try and use it like this:

Dim cb As CheckBox =
CType(GridView1.SelectedRow.FindControl("Working"), CheckBox)
If Not cb Is Nothing Then
If cb.Checked Then
System.Diagnostics.Trace.WriteLine("Checked!")
End If

Else
System.Diagnostics.Trace.WriteLine("NOT Checked")
End If

The "cb" [checkbox] is always set to "Nothing" - that is, it never
finds the control called "Working". I have double-checked my spelling
for the column name in the GridView and tried another checkbox column,
and I got the same result.

Can you see where I am going wrong? Thank you again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,480
Members
44,900
Latest member
Nell636132

Latest Threads

Top