Submit button function to update all GridView checkboxfields

G

Guest

How do I take my GridView and create a function that will update -all-
checkbox values for the submit button's OnClick event? I have posted both my
SQLDataSource and my GridView below:

<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="Int16" />
<asp:parameter Name="RevenueByMonth" Type="Int16" />
<asp:parameter Name="PDCsCCsMonthly" Type="Int16" />
<asp:parameter Name="RevenueByClient" Type="Int16" />

</UpdateParameters>

</asp:SqlDataSource>

--------------------------------------------------------------------------------------

<table id="Table1" class="main_table" cellspacing="0" cellpadding="2"
border="1" runat="server">
<tr>
<td class="main_header">Filter Tool</td>
</tr>
<tr><td colspan="2"><br />For month: <asp:Label runat="server"
id="lblCurrentMonth" /><br /><br /></td></tr>
<tr><td>
<asp:GridView
ID="gv_dashboard"
runat="server"
AutoGenerateColumns="False"
AutoGenerateEditButton = "TRUE"
DataSourceID="ds_dashboard"
CellPadding="4"
ForeColor="#333333"
ShowFooter="True"
GridLines="None"
CssClass="FormatFont">

<Columns>
<asp:TemplateField HeaderText="Cust #"
SortExpression="CustomerID">
<HeaderStyle HorizontalAlign="Left"></HeaderStyle>
<ItemTemplate>
<asp:Label runat="server" id="lblCustomerID"
Text='<%# Bind("CustomerID") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Current Month Collections"
SortExpression="Name">
<HeaderStyle HorizontalAlign="Left"></HeaderStyle>
<ItemTemplate>
<asp:checkboxfield runat="server"
datafield="CurrentMonthCollections" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Revenue By Month"
SortExpression="Name">
<HeaderStyle HorizontalAlign="Left"></HeaderStyle>
<ItemTemplate>
<asp:checkboxfield runat="server"
datafield="RevenueByMonth" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="PDCs & CCS Monthly"
SortExpression="Name">
<HeaderStyle HorizontalAlign="Left"></HeaderStyle>
<ItemTemplate>
<asp:checkboxfield runat="server"
datafield="PMonthly" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Revenue By Client"
SortExpression="Name">
<HeaderStyle HorizontalAlign="Left"></HeaderStyle>
<ItemTemplate>
<asp:checkboxfield runat="server"
datafield="RevenueByClient" />
</ItemTemplate>
</asp:TemplateField>
</Columns>

<FooterStyle BackColor="#5D7B9D" Font-Bold="True"
ForeColor="White" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<EditRowStyle BackColor="#DDDDDD" />
<SelectedRowStyle BackColor="#DDDDDD" Font-Bold="True"
ForeColor="#333333" />
<PagerStyle BackColor="#284775" ForeColor="White"
HorizontalAlign="Center" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True"
ForeColor="White" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
</td></tr>
<tr>
<td align="right">
<asp:Button CssClass="submitbutton" Text="Update" ID="Button1"
OnClick="UpdateFees" Runat="server" />
</td>
</tr>
</table>
 
N

Neutrino

If I understand correctly you want to have the GridView to update
several rows in a single postback. The GridView control does not
support this functionality, it can only have one row in edit mode at a
time and send updates to the database for one row at a time only.
However, there are work arounds. To update several rows one alternative
is to iterate the GridView.Rows collection of the gridview, and issue
the necesarry Update statements to the database (you will probably need
to use FindControl method to find the controls and extract the values
within each row).
 
G

Guest

Thanks yes...I have used that to update textboxes before but not for
checkboxfield. How can I change my Function (that does what you say,
iterates through the rows) for a checkboxfield when a checkboxfield has no ID?

Here's the code I used to do just that but with a textbox...I need to know
how to change this to update all my checkboxes:

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 Integer =
CType(gvr.FindControl("txtFeeGoalAZ"), TextBox).Text.Trim()
Dim intRevenueByMonth As Integer =
CType(gvr.FindControl("txtFeeGoalIL"), TextBox).Text.Trim()
Dim intPDCsCCsMonthly As Integer =
CType(gvr.FindControl("txtFeeGoalIL"), TextBox).Text.Trim()
Dim intRevenueByClient As Integer =
CType(gvr.FindControl("txtFeeGoalIL"), TextBox).Text.Trim()

ds_dashboard.UpdateParameters("CustomerID").DefaultValue =
intCustomerID

ds_dashboard.UpdateParameters("CurrentMonthCollections").DefaultValue =
intFeeGoalAZ
ds_dashboard.UpdateParameters("RevenueByMonth").DefaultValue
= intFeeGoalIL
ds_dashboard.UpdateParameters("PDCsCCsMonthly").DefaultValue
= intFeeGoalIL
ds_dashboard.UpdateParameters("RevenueByClient").DefaultValue
= intFeeGoalIL
ds_dashboard.Update()
End If
Next
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top