开发者

Setting value of checkbox programmatically in VB.NET

开发者 https://www.devze.com 2023-01-08 06:52 出处:网络
I can check the value of a checkbox in a GridViewRow: isChecked = CType(row.FindControl(\"chkSelect\"), CheckBox).Checked

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 persiste开发者_StackOverflow中文版d 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!


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消