Below is the error that I get when I try to access the checkbox in the data grid control.
after data grid binding I have the following code to loop through the dg control to check or leave unchecked the checkboxes. However I get the error message described below. Specified cast is not valid. What do I do? Please help. It was worked in the past but not working now. i checked the html code and that is all fine as well. Even more odd is that casting a listbox an delecting items in the same datagrid control works. Just not the checkboxes.
For i = 0 To dg1a.Items.Count - 1
flag = sqlDst.Tables("poe_data_cleaning").Rows(i)(2)
If flag = 1 Then
CType(dg1a.Items(i).FindControl("cb1a"), Checkbox).Checked = True
If flag = 0 Then
CType(dg1a.Items(i).FindControl("cb1a"), Checkbox).Checked = False
Specified cast is not valid.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidCastException: Specified cast is not valid.
Line 341: If flag = 1 Then
Line 342: CType(dg1a.Items(i).FindControl("cb1a"), Checkbox).Checked = True
Source File: C:\Inetpub\wwwroot\POE\PoeBuildModelTab.aspx.vb Line: 343
[InvalidCastException: Specified cast is not valid.]
POE.PoeBuildModelTab.LoadExistingData() in C:\Inetpub\wwwroot\POE\PoeBuildModelTab.aspx.vb:343
POE.PoeBuildModelTab.Page_Load(Object sender, EventArgs e) in C:\Inetpub\wwwroot\POE\PoeBuildModelTab.aspx.vb:69
System.Web.UI.Control.OnLoad(EventArgs e) +67