How to relate bound GridView columns to an unbound checkbox in the same row?

K

keithb

How can I relate data in the bound columns of a GridView control to an
unbound checkbox in a template column in the same row? The checkboxes
indicate which rows are to
be deleted when an update button is clicked.

Thanks,

Keith
 
T

Teemu Keiski

Hi,

depending on how youb process the rows. Assuming you loop them all through
when update button is clicked. You could just iterate

For Each row As GridViewRow in GridView1.Rows

Dim cbDelete As CheckBox = DirectCast(row.FindControl("CheckBox1"),
CheckBox)

' Accessing text in first Cell
Dim strText As String = row.Cells(0).Text
'...

'Do update etc for the row

Next

E.g you can access the entire row via the GridViewRow (same principle
applies if you do update on the row straight). If you have normal
BoundFields, then it's probably Text you are looking from them. You could
also use TemplateField's with Literals etc, when you could locate them with
FindControl similarly how I've done with CB. This has the advantage, than
chaging order of columns doesn't need changes to the code accessing the data
8since it is order-independant when using child controls with FindControl)
 

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,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top