473,408 Members | 1,730 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Getting the Value of a Checkbox in the GridView Selected Row

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.Se lectedRow.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!

Mar 6 '07 #1
2 12511
check out this code sample at ASPNet101.com:
http://aspnet101.com/aspnet101/aspne...=GridViewCheck

--
David Wier
MVP/ASPInsider
http://aspnet101.com
http://aspexpress.com
"Kirk" <lo****@hotmail.comwrote in message
news:11**********************@8g2000cwh.googlegrou ps.com...
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.Se lectedRow.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!

Mar 6 '07 #2
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.

Mar 6 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Bill44077 | last post by:
I am dynamically adding a checkbox in a gridview and I find there are several things that I cannot figure out how to address. 1. The width of the checkbox column is very wide. I've tried adding...
9
by: mike7510uk | last post by:
Hi, I am using a gridview with a templatefield containing a checkbox. I want to update the database with a 1 or 0 depending on if a checkbox is checked or unchecked (then use the 1 or 0 later on...
2
by: BenCoo | last post by:
Hello, In a gridview I've a checkbox (indicating a flag that is set or not). I fill the gridview via the wizard from ADO.NET 2.0 that generates automaticly the Insert, Update and Delete...
4
by: jeet | last post by:
Plz help me.Problem is that On the first page I display all other user with checkbox and give user option to select only two user which he wants to send message. Tell me please how I'll get those...
10
by: Mike | last post by:
I have code that is doing some updating to a record. Its getting the ID to update from the Grid. I'm passing an INT to my method to update the record. My code is working though I'm still getting an...
1
by: dhamo | last post by:
How to bind checkbox with gridview in asp.net 2.0 I take a gridview control and bind data dynamicaly using code.I taken backend tool as a Ms Access and now I want to add new column with checkbox...
3
by: =?Utf-8?B?V2FubmFiZQ==?= | last post by:
I have a gridview that has a label field and a checkbox field in it. I have the checkbox set to autopost when changed. How can I get the datakey value that is assigned to that row when a checkbox...
1
by: abhi83 | last post by:
Hi , I have a problem hope someone can help. I have created a dynamic view which contains a gridview. This gridview contains a check box column in the Template Field with the help of ITemplate...
0
by: perumalsamy R | last post by:
I am using gridview in my project.When i am clicking the checkbox ,I want to add the price value on gridview selected index changed event.can you help for my problem please help me?
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.