Link to home
Start Free TrialLog in
Avatar of dba123
dba123

asked on

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'
...
Avatar of junglerover77
junglerover77

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
Avatar of dba123

ASKER

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.
Avatar of dba123

ASKER

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")
Avatar of dba123

ASKER

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
Avatar of dba123

ASKER

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
Yes, you are right. I do forgot to force the control to the right type before using its "checked" property.
Avatar of dba123

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of GranMod
GranMod

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial