Accessing checkbox in datagrid control - Specified cast is not valid.

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
             End If
            If flag = 0 Then
                CType(dg1a.Items(i).FindControl("cb1a"), Checkbox).Checked = False
            End If
        Next









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.

Source Error:


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

Stack Trace:


[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
   System.Web.UI.Control.LoadRecursive() +35
   System.Web.UI.Page.ProcessRequestMain() +750

 
dmontgomAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ta1910Commented:
what is there on line 343
dmontgomAuthor Commented:
solved problem  request refund
dmontgomAuthor Commented:
a 3rd party control was messing up stuff

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.