Help with checkbox update function in GridView for GridView.Rows

I need help with the syntax below to finish my function which will be the update function for the onclick event for the submit button that will update all checkboxes in my GridView.  So far, I'm close but not getting quite the right syntax:

    Public Sub UpdateCustomer_DashboardGraphs(ByVal sender As Object, ByVal e As System.EventArgs)
        For Each gvr As GridViewRow In gv_dashboard.Rows
            If gvr.RowType = DataControlRowType.DataRow Then
                Dim intCustomerID As Integer = CType(gvr.FindControl("lblCustomerID"), Label).Text.Trim()
                Dim intCurrentMonthCollections As CheckBox = gvr.FindControl("chbx_CurrentMonthCollections")
                Dim intRevenueByMonth As CheckBox = gvr.FindControl("chbx_RevenueByMonth")
                Dim intPDCsCCsMonthly As CheckBox = gvr.FindControl("chbx_PDCsCCsMonthly")
                Dim intRevenueByClient As CheckBox = gvr.FindControl("chbx_RevenueByClient")

                ds_dashboard.UpdateParameters("CustomerID").DefaultValue = intCustomerID
                ds_dashboard.UpdateParameters("CurrentMonthCollections").DefaultValue = intCurrentMonthCollections
                ds_dashboard.UpdateParameters("RevenueByMonth").DefaultValue = intRevenueByMonth
                ds_dashboard.UpdateParameters("PDCsCCsMonthly").DefaultValue = intPDCsCCsMonthly
                ds_dashboard.UpdateParameters("RevenueByClient").DefaultValue = intRevenueByClient
                ds_dashboard.Update()
            End If
        Next
    End Sub

My SQLDtaSource:

        <asp:SqlDataSource
            ID="ds_dashboard"
            runat="server"
            ConnectionString="<%$ ConnectionStrings:DashboardConn %>"
            SelectCommand="Get_Customer_DashboardGraphs"
            SelectCommandType="StoredProcedure"
            UpdateCommand="Update_Customer_DashboardGraphs"
            UpdateCommandType="StoredProcedure"
            >
            <UpdateParameters>
                    <asp:Parameter Name="CustomerID" Type="Int32" />
                    <asp:Parameter Name="CurrentMonthCollections" Type="Boolean" />
                    <asp:Parameter Name="RevenueByMonth" Type="Boolean" />
                    <asp:Parameter Name="PDCsCCsMonthly" Type="Boolean" />
                    <asp:Parameter Name="RevenueByClient" Type="Boolean" />                                      
            </UpdateParameters>  
 
        </asp:SqlDataSource>


Errors I'm getting with my function:

Value of type 'System.Web.UI.WebControls.CheckBox' cannot be converted to 'String'
...
LVL 1
dba123Asked:
Who is Participating?
 
GranModCommented:
Closed, 500 points refunded.
GranMod
The Experts Exchange
Community Support Moderator of all Ages
0
 
junglerover77Commented:
The following code is wrong, how can you assign a checkbox to a value?

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
                ds_dashboard.UpdateParameters("CurrentMonthCollections").DefaultValue = intCurrentMonthCollections
                ds_dashboard.UpdateParameters("RevenueByMonth").DefaultValue = intRevenueByMonth
                ds_dashboard.UpdateParameters("PDCsCCsMonthly").DefaultValue = intPDCsCCsMonthly
                ds_dashboard.UpdateParameters("RevenueByClient").DefaultValue = intRevenueByClient
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Just Change it to:

                ds_dashboard.UpdateParameters("CurrentMonthCollections").DefaultValue = intCurrentMonthCollections.checked
                ds_dashboard.UpdateParameters("RevenueByMonth").DefaultValue = intRevenueByMonth.checked
                ds_dashboard.UpdateParameters("PDCsCCsMonthly").DefaultValue = intPDCsCCsMonthly.checked
                ds_dashboard.UpdateParameters("RevenueByClient").DefaultValue = intRevenueByClient.checked
0
 
dba123Author Commented:
hehehe, Jungle, I have to chuckle ast your reponse a little...Yes, I know it's wrong :)  That's why I'm posting this question, because I couldn't find the right syntax or an article explaining this anywhere so I posted this in EE>  I don't know how I can assigne a checkbox to a value, I was just experimenting since I had nothing to go by.

Thank you, I will try your suggestion.
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
dba123Author Commented:
what about this part though:

                Dim intCurrentMonthCollections As CheckBox = CType(gvr.FindControl("chbx_CurrentMonthCollections"), CheckBox)
                Dim intRevenueByMonth As CheckBox = gvr.FindControl("chbx_RevenueByMonth")
                Dim intPDCsCCsMonthly As CheckBox = gvr.FindControl("chbx_PDCsCCsMonthly")
                Dim intRevenueByClient As CheckBox = gvr.FindControl("chbx_RevenueByClient")
0
 
dba123Author Commented:
If I try this, I get an error saying it cannot convert to Boolean

                Dim intCurrentMonthCollections As Boolean = CType(gvr.FindControl("chbx_CurrentMonthCollections"), CheckBox)
                Dim intRevenueByMonth As Boolean = gvr.FindControl("chbx_RevenueByMonth")
                Dim intPDCsCCsMonthly As Boolean = gvr.FindControl("chbx_PDCsCCsMonthly")
                Dim intRevenueByClient As Boolean = gvr.FindControl("chbx_RevenueByClient")

Error: Value of type 'System.Web.UI.Control' cannot be converted to 'Boolean'.

so what is the correct syntax?  It's amazing to me that I have to search so hard to find this on the net
0
 
dba123Author Commented:
Ok, I played around with it, I may have it?

    Public Sub UpdateCustomer_DashboardGraphs(ByVal sender As Object, ByVal e As System.EventArgs)
        For Each gvr As GridViewRow In gv_dashboard.Rows
            If gvr.RowType = DataControlRowType.DataRow Then
                Dim intCustomerID As Integer = CType(gvr.FindControl("lblCustomerID"), Label).Text.Trim()
                Dim intCurrentMonthCollections As Boolean = CType(gvr.FindControl("chbx_CurrentMonthCollections"), CheckBox).Checked
                Dim intRevenueByMonth As Boolean = CType(gvr.FindControl("chbx_RevenueByMonth"), CheckBox).Checked
                Dim intPDCsCCsMonthly As Boolean = CType(gvr.FindControl("chbx_PDCsCCsMonthly"), CheckBox).Checked
                Dim intRevenueByClient As Boolean = CType(gvr.FindControl("chbx_RevenueByClient"), CheckBox).Checked

                'ds_dashboard.UpdateParameters("CustomerID").DefaultValue = intCustomerID
                ds_dashboard.UpdateParameters("CurrentMonthCollections").DefaultValue = intCurrentMonthCollections
                ds_dashboard.UpdateParameters("RevenueByMonth").DefaultValue = intRevenueByMonth
                ds_dashboard.UpdateParameters("PDCsCCsMonthly").DefaultValue = intPDCsCCsMonthly
                ds_dashboard.UpdateParameters("RevenueByClient").DefaultValue = intRevenueByClient
                ds_dashboard.Update()
            End If
        Next
    End Sub
0
 
junglerover77Commented:
Yes, you are right. I do forgot to force the control to the right type before using its "checked" property.
0
 
dba123Author Commented:
And the answer is:

    Public Sub UpdateCustomer_DashboardGraphs(ByVal sender As Object, ByVal e As System.EventArgs)
        For Each gvr As GridViewRow In gv_dashboard.Rows
            If gvr.RowType = DataControlRowType.DataRow Then

....

                '//--Checkboxes
                Dim bolCurrentMonthCollections As Boolean = CType(gvr.FindControl("chbx_CurrentMonthCollections"), CheckBox).Checked
                Dim bolRevenueByMonth As Boolean = CType(gvr.FindControl("chbx_RevenueByMonth"), CheckBox).Checked
                Dim bolPDCsCCsMonthly As Boolean = CType(gvr.FindControl("chbx_PDCsCCsMonthly"), CheckBox).Checked
                Dim bolRevenueByClient As Boolean = CType(gvr.FindControl("chbx_RevenueByClient"), CheckBox).Checked
                Dim bolArizona As Boolean = CType(gvr.FindControl("chbx_Arizona"), CheckBox).Checked
                Dim bolIllinois As Boolean = CType(gvr.FindControl("chbx_Illinois"), CheckBox).Checked

...

                ds_dashboard.Update()
            End If
        Next
    End Sub
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.