troubleshooting Question

Using and with dynamic checkboxes to check the checked status within a Gridview where created with a placeholder

Avatar of ThePrettyGeek
ThePrettyGeekFlag for United States of America asked on
.NET ProgrammingASP.NET
19 Comments1 Solution1784 ViewsLast Modified:
I have a Gridview that pulls data from MySQL and then displays it along side a column of checkboxes that are created via a ItemTemplage in the html. this works wonderfully for creating it but problem lies in checking the status of these check boxes.

I first tried just using the checkbox.checked =  true or false method but because its created dynamically the VB code doesn't see it.

I thought I had figured it out at one pont with the EnabledViewState in the VB code where it checked - if CheckBox IsNot Nothing And CheckBox.EnableViewState = True Then bla bla bla but all that was checking was to see if view state was enabled and it was which would then select all of the items and run the code under the if statment up until the checkbox was ticked. so it was updating all sql entries above the correct one as well.

What I need it to check is still If CheckBox IsNot Nothing And CheckBox.Checked = True Then
but it constantly returns false.

I thought I had found somewhat of an answer with
and other than nameing things a bit differently it may as well have been a direct copy and paste of the code but this too failed. I tried using the CheckChanged and the OnCheckChaned properties but VS didnt recognize them as valid properties of the command,

I thouht there may be someway to use the attributes property and played around with variations of CheckBox.Attributes(ViewState(Checked)) and Im still not convinced Im 100% wrong with going this direction, I just couldnt figure out the exact wording on it.

In any event, Im back here begging for help
' VB.NET Code
Dim tr As TableRow
Dim RowCounter As Integer = 0

For Each tr In GridViewID.Rows
  Dim cb As CheckBox = GridViewID.Rows(RowCounter).Cells(0).FindControl("CheckBoxID")
  If cb IsNot Nothing And cb.Checked = True Then
    'Code to pull data from GridViewID and compare to DB
    'Code to Update MySQL Database
    RowCounter = +1
  End If

<!--ASP / HTML CODE-->
                <asp:GridView ID="GridViewID" runat="server">
                       <asp:TemplateField HeaderText="CheckBox Column">
                         <asp:CheckBox runat="server" ID="CheckBoxID" Checked="false" EnableViewState="true" />                                            

Open in new window


Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 19 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 19 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros