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_DashboardGr aphs(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("lbl CustomerID "), Label).Text.Trim()
Dim intCurrentMonthCollections As CheckBox = gvr.FindControl("chbx_Curr entMonthCo llections" )
Dim intRevenueByMonth As CheckBox = gvr.FindControl("chbx_Reve nueByMonth ")
Dim intPDCsCCsMonthly As CheckBox = gvr.FindControl("chbx_PDCs CCsMonthly ")
Dim intRevenueByClient As CheckBox = gvr.FindControl("chbx_Reve nueByClien t")
ds_dashboard.UpdateParamet ers("Custo merID").De faultValue = intCustomerID
ds_dashboard.UpdateParamet ers("Curre ntMonthCol lections") .DefaultVa lue = intCurrentMonthCollections
ds_dashboard.UpdateParamet ers("Reven ueByMonth" ).DefaultV alue = intRevenueByMonth
ds_dashboard.UpdateParamet ers("PDCsC CsMonthly" ).DefaultV alue = intPDCsCCsMonthly
ds_dashboard.UpdateParamet ers("Reven ueByClient ").Default Value = intRevenueByClient
ds_dashboard.Update()
End If
Next
End Sub
My SQLDtaSource:
<asp:SqlDataSource
ID="ds_dashboard"
runat="server"
ConnectionString="<%$ ConnectionStrings:Dashboar dConn %>"
SelectCommand="Get_Custome r_Dashboar dGraphs"
SelectCommandType="StoredP rocedure"
UpdateCommand="Update_Cust omer_Dashb oardGraphs "
UpdateCommandType="StoredP rocedure"
>
<UpdateParameters>
<asp:Parameter Name="CustomerID" Type="Int32" />
<asp:Parameter Name="CurrentMonthCollecti ons" 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'
...
Public Sub UpdateCustomer_DashboardGr
For Each gvr As GridViewRow In gv_dashboard.Rows
If gvr.RowType = DataControlRowType.DataRow
Dim intCustomerID As Integer = CType(gvr.FindControl("lbl
Dim intCurrentMonthCollections
Dim intRevenueByMonth As CheckBox = gvr.FindControl("chbx_Reve
Dim intPDCsCCsMonthly As CheckBox = gvr.FindControl("chbx_PDCs
Dim intRevenueByClient As CheckBox = gvr.FindControl("chbx_Reve
ds_dashboard.UpdateParamet
ds_dashboard.UpdateParamet
ds_dashboard.UpdateParamet
ds_dashboard.UpdateParamet
ds_dashboard.UpdateParamet
ds_dashboard.Update()
End If
Next
End Sub
My SQLDtaSource:
<asp:SqlDataSource
ID="ds_dashboard"
runat="server"
ConnectionString="<%$ ConnectionStrings:Dashboar
SelectCommand="Get_Custome
SelectCommandType="StoredP
UpdateCommand="Update_Cust
UpdateCommandType="StoredP
>
<UpdateParameters>
<asp:Parameter Name="CustomerID" Type="Int32" />
<asp:Parameter Name="CurrentMonthCollecti
<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
...
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.
Thank you, I will try your suggestion.
ASKER
what about this part though:
Dim intCurrentMonthCollections As CheckBox = CType(gvr.FindControl("chb x_CurrentM onthCollec tions"), CheckBox)
Dim intRevenueByMonth As CheckBox = gvr.FindControl("chbx_Reve nueByMonth ")
Dim intPDCsCCsMonthly As CheckBox = gvr.FindControl("chbx_PDCs CCsMonthly ")
Dim intRevenueByClient As CheckBox = gvr.FindControl("chbx_Reve nueByClien t")
Dim intCurrentMonthCollections
Dim intRevenueByMonth As CheckBox = gvr.FindControl("chbx_Reve
Dim intPDCsCCsMonthly As CheckBox = gvr.FindControl("chbx_PDCs
Dim intRevenueByClient As CheckBox = gvr.FindControl("chbx_Reve
ASKER
If I try this, I get an error saying it cannot convert to Boolean
Dim intCurrentMonthCollections As Boolean = CType(gvr.FindControl("chb x_CurrentM onthCollec tions"), CheckBox)
Dim intRevenueByMonth As Boolean = gvr.FindControl("chbx_Reve nueByMonth ")
Dim intPDCsCCsMonthly As Boolean = gvr.FindControl("chbx_PDCs CCsMonthly ")
Dim intRevenueByClient As Boolean = gvr.FindControl("chbx_Reve nueByClien t")
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
Dim intCurrentMonthCollections
Dim intRevenueByMonth As Boolean = gvr.FindControl("chbx_Reve
Dim intPDCsCCsMonthly As Boolean = gvr.FindControl("chbx_PDCs
Dim intRevenueByClient As Boolean = gvr.FindControl("chbx_Reve
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
ASKER
Ok, I played around with it, I may have it?
Public Sub UpdateCustomer_DashboardGr aphs(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("lbl CustomerID "), Label).Text.Trim()
Dim intCurrentMonthCollections As Boolean = CType(gvr.FindControl("chb x_CurrentM onthCollec tions"), CheckBox).Checked
Dim intRevenueByMonth As Boolean = CType(gvr.FindControl("chb x_RevenueB yMonth"), CheckBox).Checked
Dim intPDCsCCsMonthly As Boolean = CType(gvr.FindControl("chb x_PDCsCCsM onthly"), CheckBox).Checked
Dim intRevenueByClient As Boolean = CType(gvr.FindControl("chb x_RevenueB yClient"), CheckBox).Checked
'ds_dashboard.UpdateParame ters("Cust omerID").D efaultValu e = intCustomerID
ds_dashboard.UpdateParamet ers("Curre ntMonthCol lections") .DefaultVa lue = intCurrentMonthCollections
ds_dashboard.UpdateParamet ers("Reven ueByMonth" ).DefaultV alue = intRevenueByMonth
ds_dashboard.UpdateParamet ers("PDCsC CsMonthly" ).DefaultV alue = intPDCsCCsMonthly
ds_dashboard.UpdateParamet ers("Reven ueByClient ").Default Value = intRevenueByClient
ds_dashboard.Update()
End If
Next
End Sub
Public Sub UpdateCustomer_DashboardGr
For Each gvr As GridViewRow In gv_dashboard.Rows
If gvr.RowType = DataControlRowType.DataRow
Dim intCustomerID As Integer = CType(gvr.FindControl("lbl
Dim intCurrentMonthCollections
Dim intRevenueByMonth As Boolean = CType(gvr.FindControl("chb
Dim intPDCsCCsMonthly As Boolean = CType(gvr.FindControl("chb
Dim intRevenueByClient As Boolean = CType(gvr.FindControl("chb
'ds_dashboard.UpdateParame
ds_dashboard.UpdateParamet
ds_dashboard.UpdateParamet
ds_dashboard.UpdateParamet
ds_dashboard.UpdateParamet
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.
ASKER
And the answer is:
Public Sub UpdateCustomer_DashboardGr aphs(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("chb x_CurrentM onthCollec tions"), CheckBox).Checked
Dim bolRevenueByMonth As Boolean = CType(gvr.FindControl("chb x_RevenueB yMonth"), CheckBox).Checked
Dim bolPDCsCCsMonthly As Boolean = CType(gvr.FindControl("chb x_PDCsCCsM onthly"), CheckBox).Checked
Dim bolRevenueByClient As Boolean = CType(gvr.FindControl("chb x_RevenueB yClient"), CheckBox).Checked
Dim bolArizona As Boolean = CType(gvr.FindControl("chb x_Arizona" ), CheckBox).Checked
Dim bolIllinois As Boolean = CType(gvr.FindControl("chb x_Illinois "), CheckBox).Checked
...
ds_dashboard.Update()
End If
Next
End Sub
Public Sub UpdateCustomer_DashboardGr
For Each gvr As GridViewRow In gv_dashboard.Rows
If gvr.RowType = DataControlRowType.DataRow
....
'//--Checkboxes
Dim bolCurrentMonthCollections
Dim bolRevenueByMonth As Boolean = CType(gvr.FindControl("chb
Dim bolPDCsCCsMonthly As Boolean = CType(gvr.FindControl("chb
Dim bolRevenueByClient As Boolean = CType(gvr.FindControl("chb
Dim bolArizona As Boolean = CType(gvr.FindControl("chb
Dim bolIllinois As Boolean = CType(gvr.FindControl("chb
...
ds_dashboard.Update()
End If
Next
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
''''''''''''''''''''''''''
ds_dashboard.UpdateParamet
ds_dashboard.UpdateParamet
ds_dashboard.UpdateParamet
ds_dashboard.UpdateParamet
''''''''''''''''''''''''''
Just Change it to:
ds_dashboard.UpdateParamet
ds_dashboard.UpdateParamet
ds_dashboard.UpdateParamet
ds_dashboard.UpdateParamet