0

I can check the value of a checkbox in a GridViewRow:

isChecked = CType(row.FindControl("chkSelect"), CheckBox).Checked

But what's baking my noodle is trying to figure out how to programmatically set a checkbox to checked.

The scenario is I have some rows in a GridView that are associated to another value in a dropdown. So, when I select the value in the dropdown, I'd like the checkboxes in the GridViewRows that are associated with that value to be already checked.

Problem: The check value is not persisted in the database. There's no field for it. The checkbox on the GridViewRows is an ASP TemplateField.

So I iterate through the rows and would like to check whichever checkboxes I need to based on whatever condition.

Hope I was sufficiently clear!

Bill
  • 3
  • 1
  • 3

1 Answers1

2

You should be able to do it like this

CType(row.FindControl("chkSelect"), CheckBox).Checked = True

or

CType(row.Cells(index).Controls(controlIndex), CheckBox).Checked = True

Also, see the following article for more information.

Garett
  • 16,632
  • 5
  • 55
  • 63
  • Hm, I could have sworn I tried something like your number 1 option there.. I guess it's late, I'm tired, and I must have missed something! I got it to work by declaring a CheckBox variable and assigning the chkSelect value to that, but I reverted back to your option above as that was what I was striving for originally. Many thanks! – Bill Jul 23 '10 at 04:45