dba123
asked on
Add Grand Total Row at bottom of GridView
How can I add a last row in my Gridview that shows a Grand Total of the 2 Budget columns?
<asp:GridView
ID="gv_dashboard"
runat="server"
AutoGenerateColumns="False "
DataSourceID="ds_dashboard "
CellPadding="4"
ForeColor="#333333"
ShowFooter="True"
GridLines="None"
CssClass="FormatFont">
<Columns>
<asp:TemplateField HeaderText="Cust #" SortExpression="CustomerID ">
<HeaderStyle HorizontalAlign="center">< /HeaderSty le>
<ItemTemplate>
<asp:Label runat="server" id="lblCustomerID" Text='<%# Bind("Customer") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="AZ Budget" SortExpression="Name" ItemStyle-HorizontalAlign= "Center">
<HeaderStyle HorizontalAlign="Left"></H eaderStyle >
<ItemTemplate>
<asp:TextBox width="55px" MaxLength="10" ID="txtAZBudget" Text='<%# Bind("AZBudget") %>' runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="IL Budget" SortExpression="Name" ItemStyle-HorizontalAlign= "Center">
<HeaderStyle HorizontalAlign="Left"></H eaderStyle >
<ItemTemplate>
<asp:TextBox width="55px" MaxLength="10" ID="txtILBudget" Text='<%# Bind("ILBudget") %>' runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="AZ" SortExpression="Name" ItemStyle-HorizontalAlign= "Center">
<HeaderStyle HorizontalAlign="center">< /HeaderSty le>
<ItemTemplate>
<asp:checkbox runat="server" Id="chbx_Arizona" Checked='<%# Bind("Arizona") %>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="IL" SortExpression="Name" ItemStyle-HorizontalAlign= "Center">
<HeaderStyle HorizontalAlign="center">< /HeaderSty le>
<ItemTemplate>
<asp:checkbox runat="server" Id="chbx_Illinois" Checked='<%# Bind("Illinois") %>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Current Month Collections" SortExpression="Name" ItemStyle-HorizontalAlign= "Center">
<HeaderStyle HorizontalAlign="center">< /HeaderSty le>
<ItemTemplate>
<asp:checkbox runat="server" Id="chbx_CurrentMonthColle ctions" Checked='<%# Bind("CurrentMonthCollecti ons") %>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Revenue By Month" SortExpression="Name" ItemStyle-HorizontalAlign= "Center">
<HeaderStyle HorizontalAlign="center">< /HeaderSty le>
<ItemTemplate>
<asp:checkbox runat="server" Id="chbx_RevenueByMonth" Checked='<%# Bind("RevenueByMonth") %>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="PDCs & CCS Monthly" SortExpression="Name" ItemStyle-HorizontalAlign= "Center">
<HeaderStyle HorizontalAlign="center">< /HeaderSty le>
<ItemTemplate>
<asp:checkbox runat="server" Id="chbx_PDCsCCsMonthly" Checked='<%# Bind("PDCsCCsMonthly") %>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Revenue By Client" SortExpression="Name" ItemStyle-HorizontalAlign= "Center">
<HeaderStyle HorizontalAlign="center">< /HeaderSty le>
<ItemTemplate>
<asp:checkbox runat="server" Id="chbx_RevenueByClient" Checked='<%# Bind("RevenueByClient") %>'/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<asp:GridView
ID="gv_dashboard"
runat="server"
AutoGenerateColumns="False
DataSourceID="ds_dashboard
CellPadding="4"
ForeColor="#333333"
ShowFooter="True"
GridLines="None"
CssClass="FormatFont">
<Columns>
<asp:TemplateField HeaderText="Cust #" SortExpression="CustomerID
<HeaderStyle HorizontalAlign="center"><
<ItemTemplate>
<asp:Label runat="server" id="lblCustomerID" Text='<%# Bind("Customer") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="AZ Budget" SortExpression="Name" ItemStyle-HorizontalAlign=
<HeaderStyle HorizontalAlign="Left"></H
<ItemTemplate>
<asp:TextBox width="55px" MaxLength="10" ID="txtAZBudget" Text='<%# Bind("AZBudget") %>' runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="IL Budget" SortExpression="Name" ItemStyle-HorizontalAlign=
<HeaderStyle HorizontalAlign="Left"></H
<ItemTemplate>
<asp:TextBox width="55px" MaxLength="10" ID="txtILBudget" Text='<%# Bind("ILBudget") %>' runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="AZ" SortExpression="Name" ItemStyle-HorizontalAlign=
<HeaderStyle HorizontalAlign="center"><
<ItemTemplate>
<asp:checkbox runat="server" Id="chbx_Arizona" Checked='<%# Bind("Arizona") %>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="IL" SortExpression="Name" ItemStyle-HorizontalAlign=
<HeaderStyle HorizontalAlign="center"><
<ItemTemplate>
<asp:checkbox runat="server" Id="chbx_Illinois" Checked='<%# Bind("Illinois") %>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Current Month Collections" SortExpression="Name" ItemStyle-HorizontalAlign=
<HeaderStyle HorizontalAlign="center"><
<ItemTemplate>
<asp:checkbox runat="server" Id="chbx_CurrentMonthColle
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Revenue By Month" SortExpression="Name" ItemStyle-HorizontalAlign=
<HeaderStyle HorizontalAlign="center"><
<ItemTemplate>
<asp:checkbox runat="server" Id="chbx_RevenueByMonth" Checked='<%# Bind("RevenueByMonth") %>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="PDCs & CCS Monthly" SortExpression="Name" ItemStyle-HorizontalAlign=
<HeaderStyle HorizontalAlign="center"><
<ItemTemplate>
<asp:checkbox runat="server" Id="chbx_PDCsCCsMonthly" Checked='<%# Bind("PDCsCCsMonthly") %>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Revenue By Client" SortExpression="Name" ItemStyle-HorizontalAlign=
<HeaderStyle HorizontalAlign="center"><
<ItemTemplate>
<asp:checkbox runat="server" Id="chbx_RevenueByClient" Checked='<%# Bind("RevenueByClient") %>'/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
Inside your Footer template put <asp:Label runat="server" id="lblTotal" />
Then in your codebehind
lblTotal.Text = TotalAZBudget
Then in your codebehind
lblTotal.Text = TotalAZBudget
ASKER
Ok, tried this, still getting error and not sure if I should be placing the AZTotal.ToText - TotalAZBudget in the Page load or not
Parser Error Message: System.Web.UI.WebControls. DataContro lFieldColl ection must have items of type 'System.Web.UI.WebControls .DataContr olField'. 'FooterTemplate' is of type 'System.Web.UI.HtmlControl s.HtmlGene ricControl '.
Source Error:
Line 105: </ItemTemplate>
Line 106: </asp:TemplateField>
Line 107: <FooterTemplate>
Line 108: <asp:Label runat="server" id="lblAZTotal" />
Line 109: </FooterTemplate>
aspx:
-------
<FooterTemplate>
<asp:Label runat="server" id="lblAZTotal" />
</FooterTemplate>
code-behind:
------------------
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim lblAZTotal As Label
lblAZTotal.Text = TotalAZBudget
End Sub
....
Dim TotalAZBudget As Integer
Function GetAZBudget(ByVal AZBudget As Integer) As Integer
TotalAZBudget += AZBudget
Return AZBudget
End Function
Function GetAZBudgetTotal() As Integer
Return TotalAZBudget
End Function
Parser Error Message: System.Web.UI.WebControls.
Source Error:
Line 105: </ItemTemplate>
Line 106: </asp:TemplateField>
Line 107: <FooterTemplate>
Line 108: <asp:Label runat="server" id="lblAZTotal" />
Line 109: </FooterTemplate>
aspx:
-------
<FooterTemplate>
<asp:Label runat="server" id="lblAZTotal" />
</FooterTemplate>
code-behind:
------------------
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim lblAZTotal As Label
lblAZTotal.Text = TotalAZBudget
End Sub
....
Dim TotalAZBudget As Integer
Function GetAZBudget(ByVal AZBudget As Integer) As Integer
TotalAZBudget += AZBudget
Return AZBudget
End Function
Function GetAZBudgetTotal() As Integer
Return TotalAZBudget
End Function
ASKER
and before when I had <%# GetAZTotal().ToString("N2" ) %> in there, I got this error:
ASP.NET runtime error: Code blocks are not supported in this context
why was that?
ASP.NET runtime error: Code blocks are not supported in this context
why was that?
ASKER
I'm all messed up here, hold on...
Here is a solid site to explain how to get it to work.
http://msdn2.microsoft.com/en-US/library/system.web.ui.webcontrols.templatefield.footertemplate.aspx
http://msdn2.microsoft.com/en-US/library/system.web.ui.webcontrols.templatefield.footertemplate.aspx
ASKER
How do I get rid of this error, I still don't understand this damn error message. Do I need to ad a missing namespace or do I just not have it placed in the correct area within my DataGrid?
Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Parser Error Message: System.Web.UI.WebControls. DataContro lFieldColl ection must have items of type 'System.Web.UI.WebControls .DataContr olField'. 'FooterTemplate' is of type 'System.Web.UI.HtmlControl s.HtmlGene ricControl '.
Source Error:
Line 105: </ItemTemplate>
Line 106: </asp:TemplateField>
Line 107: <FooterTemplate>
Line 108: <asp:Label runat="server" id="AZTotal_Label" />
Line 109: </FooterTemplate
Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Parser Error Message: System.Web.UI.WebControls.
Source Error:
Line 105: </ItemTemplate>
Line 106: </asp:TemplateField>
Line 107: <FooterTemplate>
Line 108: <asp:Label runat="server" id="AZTotal_Label" />
Line 109: </FooterTemplate
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
but won't that create another column?
No it will tell it under which column the footer should reside....
So if you want it to be a total under 'AZ Budget' then have
<asp:TemplateField HeaderText="AZ Budget" SortExpression="Name" ItemStyle-HorizontalAlign= "Center">
<HeaderStyle HorizontalAlign="Left"></H eaderStyle >
<ItemTemplate>
<asp:TextBox width="55px" MaxLength="10" ID="txtAZBudget" Text='<%# Bind("AZBudget") %>' runat="server" />
</ItemTemplate>
<FooterTemplate>
<asp:Label runat="server" id="AZTotal_Label" />
</FooterTemplate
</asp:TemplateField>
So if you want it to be a total under 'AZ Budget' then have
<asp:TemplateField HeaderText="AZ Budget" SortExpression="Name" ItemStyle-HorizontalAlign=
<HeaderStyle HorizontalAlign="Left"></H
<ItemTemplate>
<asp:TextBox width="55px" MaxLength="10" ID="txtAZBudget" Text='<%# Bind("AZBudget") %>' runat="server" />
</ItemTemplate>
<FooterTemplate>
<asp:Label runat="server" id="AZTotal_Label" />
</FooterTemplate
</asp:TemplateField>
ASKER
Ok, the grid is rendering again, but I'm not seeing anything here in the label for AZBudget.
aspx:
----------
<asp:GridView
ID="gv_dashboard"
runat="server"
AutoGenerateColumns="False "
DataSourceID="ds_dashboard "
CellPadding="4"
ForeColor="#333333"
ShowFooter="True"
GridLines="None"
CssClass="FormatFont">
<Columns>
<asp:TemplateField HeaderText="Cust #" SortExpression="CustomerID ">
<HeaderStyle HorizontalAlign="center">< /HeaderSty le>
<ItemTemplate>
<asp:Label runat="server" id="lblCustomerID" Text='<%# Bind("Customer") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="AZ Budget" SortExpression="Name" ItemStyle-HorizontalAlign= "Center">
<HeaderStyle HorizontalAlign="Left"></H eaderStyle >
<ItemTemplate>
<asp:TextBox width="55px" MaxLength="10" ID="txtAZBudget" Text='<%# Bind("AZBudget") %>' runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="IL Budget" SortExpression="Name" ItemStyle-HorizontalAlign= "Center">
<HeaderStyle HorizontalAlign="Left"></H eaderStyle >
<ItemTemplate>
<asp:TextBox width="55px" MaxLength="10" ID="txtILBudget" Text='<%# Bind("ILBudget") %>' runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="AZ" SortExpression="Name" ItemStyle-HorizontalAlign= "Center">
<HeaderStyle HorizontalAlign="center">< /HeaderSty le>
<ItemTemplate>
<asp:checkbox runat="server" Id="chbx_Arizona" Checked='<%# Bind("Arizona") %>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="IL" SortExpression="Name" ItemStyle-HorizontalAlign= "Center">
<HeaderStyle HorizontalAlign="center">< /HeaderSty le>
<ItemTemplate>
<asp:checkbox runat="server" Id="chbx_Illinois" Checked='<%# Bind("Illinois") %>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Current Month Collections" SortExpression="Name" ItemStyle-HorizontalAlign= "Center">
<HeaderStyle HorizontalAlign="center">< /HeaderSty le>
<ItemTemplate>
<asp:checkbox runat="server" Id="chbx_CurrentMonthColle ctions" Checked='<%# Bind("CurrentMonthCollecti ons") %>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Revenue By Month" SortExpression="Name" ItemStyle-HorizontalAlign= "Center">
<HeaderStyle HorizontalAlign="center">< /HeaderSty le>
<ItemTemplate>
<asp:checkbox runat="server" Id="chbx_RevenueByMonth" Checked='<%# Bind("RevenueByMonth") %>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="PDCs & CCS Monthly" SortExpression="Name" ItemStyle-HorizontalAlign= "Center">
<HeaderStyle HorizontalAlign="center">< /HeaderSty le>
<ItemTemplate>
<asp:checkbox runat="server" Id="chbx_PDCsCCsMonthly" Checked='<%# Bind("PDCsCCsMonthly") %>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Revenue By Client" SortExpression="Name" ItemStyle-HorizontalAlign= "Center">
<HeaderStyle HorizontalAlign="center">< /HeaderSty le>
<ItemTemplate>
<asp:checkbox runat="server" Id="chbx_RevenueByClient" Checked='<%# Bind("RevenueByClient") %>'/>
</ItemTemplate>
<FooterTemplate>
<asp:Label runat="server" id="AZTotal_Label" />
</FooterTemplate>
</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>
Code-behind:
-----------------
..
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
....
Dim gv_dashboard As GridView
' Create a variable to store the order total.
Private AZBudgetTotal As Integer = 0
Sub gv_dashboard_RowCreated(By Val sender As Object, ByVal e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.Footer Then
' Get the AZTotal_Label Label control in the footer row.
Dim AZTotal As Label = CType(e.Row.FindControl("A ZTotal_Lab el"), Label)
' Display the grand total of the AZBudget Column formatted as currency.
If (Not AZTotal Is Nothing) Then
AZTotal.Text = AZBudgetTotal.ToString("c0 ")
End If
End If
End Sub
Sub gv_dashboard_RowDataBound( ByVal sender As Object, ByVal e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
' Get the cell that contains the item total.
Dim cell As TableCell = e.Row.Cells(1)
' Get the DataBoundLiteralControl control that contains the
' data bound value.
Dim boundControl As DataBoundLiteralControl = CType(cell.Controls(1), DataBoundLiteralControl)
' Remove the '$' character so that the type converter works properly.
Dim itemTotal As String = boundControl.Text.Replace( "$", "")
' Add the total for an item (row) to the order total.
AZBudgetTotal += Convert.ToDecimal(itemTota l)
End If
End Sub
aspx:
----------
<asp:GridView
ID="gv_dashboard"
runat="server"
AutoGenerateColumns="False
DataSourceID="ds_dashboard
CellPadding="4"
ForeColor="#333333"
ShowFooter="True"
GridLines="None"
CssClass="FormatFont">
<Columns>
<asp:TemplateField HeaderText="Cust #" SortExpression="CustomerID
<HeaderStyle HorizontalAlign="center"><
<ItemTemplate>
<asp:Label runat="server" id="lblCustomerID" Text='<%# Bind("Customer") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="AZ Budget" SortExpression="Name" ItemStyle-HorizontalAlign=
<HeaderStyle HorizontalAlign="Left"></H
<ItemTemplate>
<asp:TextBox width="55px" MaxLength="10" ID="txtAZBudget" Text='<%# Bind("AZBudget") %>' runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="IL Budget" SortExpression="Name" ItemStyle-HorizontalAlign=
<HeaderStyle HorizontalAlign="Left"></H
<ItemTemplate>
<asp:TextBox width="55px" MaxLength="10" ID="txtILBudget" Text='<%# Bind("ILBudget") %>' runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="AZ" SortExpression="Name" ItemStyle-HorizontalAlign=
<HeaderStyle HorizontalAlign="center"><
<ItemTemplate>
<asp:checkbox runat="server" Id="chbx_Arizona" Checked='<%# Bind("Arizona") %>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="IL" SortExpression="Name" ItemStyle-HorizontalAlign=
<HeaderStyle HorizontalAlign="center"><
<ItemTemplate>
<asp:checkbox runat="server" Id="chbx_Illinois" Checked='<%# Bind("Illinois") %>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Current Month Collections" SortExpression="Name" ItemStyle-HorizontalAlign=
<HeaderStyle HorizontalAlign="center"><
<ItemTemplate>
<asp:checkbox runat="server" Id="chbx_CurrentMonthColle
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Revenue By Month" SortExpression="Name" ItemStyle-HorizontalAlign=
<HeaderStyle HorizontalAlign="center"><
<ItemTemplate>
<asp:checkbox runat="server" Id="chbx_RevenueByMonth" Checked='<%# Bind("RevenueByMonth") %>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="PDCs & CCS Monthly" SortExpression="Name" ItemStyle-HorizontalAlign=
<HeaderStyle HorizontalAlign="center"><
<ItemTemplate>
<asp:checkbox runat="server" Id="chbx_PDCsCCsMonthly" Checked='<%# Bind("PDCsCCsMonthly") %>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Revenue By Client" SortExpression="Name" ItemStyle-HorizontalAlign=
<HeaderStyle HorizontalAlign="center"><
<ItemTemplate>
<asp:checkbox runat="server" Id="chbx_RevenueByClient" Checked='<%# Bind("RevenueByClient") %>'/>
</ItemTemplate>
<FooterTemplate>
<asp:Label runat="server" id="AZTotal_Label" />
</FooterTemplate>
</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>
Code-behind:
-----------------
..
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
....
Dim gv_dashboard As GridView
' Create a variable to store the order total.
Private AZBudgetTotal As Integer = 0
Sub gv_dashboard_RowCreated(By
If e.Row.RowType = DataControlRowType.Footer Then
' Get the AZTotal_Label Label control in the footer row.
Dim AZTotal As Label = CType(e.Row.FindControl("A
' Display the grand total of the AZBudget Column formatted as currency.
If (Not AZTotal Is Nothing) Then
AZTotal.Text = AZBudgetTotal.ToString("c0
End If
End If
End Sub
Sub gv_dashboard_RowDataBound(
If e.Row.RowType = DataControlRowType.DataRow
' Get the cell that contains the item total.
Dim cell As TableCell = e.Row.Cells(1)
' Get the DataBoundLiteralControl control that contains the
' data bound value.
Dim boundControl As DataBoundLiteralControl = CType(cell.Controls(1), DataBoundLiteralControl)
' Remove the '$' character so that the type converter works properly.
Dim itemTotal As String = boundControl.Text.Replace(
' Add the total for an item (row) to the order total.
AZBudgetTotal += Convert.ToDecimal(itemTota
End If
End Sub
ASKER
also, I don't think this is in the right spot still, I feel ilke it should be somewhere else on its own, not in the last ItemTemplateField
<FooterTemplate>
<asp:Label runat="server" id="AZTotal_Label" />
</FooterTemplate>
<FooterTemplate>
<asp:Label runat="server" id="AZTotal_Label" />
</FooterTemplate>
To see if it is in the right spot try this
<FooterTemplate>
<asp:Label runat="server" id="AZTotal_Label" Text="Testing" />
</FooterTemplate>
You can then see where it is meant to be...
Try changing
Private AZBudgetTotal As Integer = 0
to
Public AZBudgetTotal As Integer = 0
<FooterTemplate>
<asp:Label runat="server" id="AZTotal_Label" Text="Testing" />
</FooterTemplate>
You can then see where it is meant to be...
Try changing
Private AZBudgetTotal As Integer = 0
to
Public AZBudgetTotal As Integer = 0
ASKER
>>>To see if it is in the right spot try this
what do you mean by spot try...
>>>Try changing
Private AZBudgetTotal As Integer = 0
to
Public AZBudgetTotal As Integer = 0
Did that, didn't make a difference when the Grid was rendered...
what do you mean by spot try...
>>>Try changing
Private AZBudgetTotal As Integer = 0
to
Public AZBudgetTotal As Integer = 0
Did that, didn't make a difference when the Grid was rendered...
ASKER
nevermind I see, yea, good idea, let me try that label and see where the footer field is ending up for your spot try
ASKER
ok, cool thanks. I need to add the footer right here since it will then show below that row then:
<asp:TemplateField HeaderText="AZ Budget" SortExpression="Name" ItemStyle-HorizontalAlign= "Center">
<HeaderStyle HorizontalAlign="Left"></H eaderStyle >
<ItemTemplate>
<asp:TextBox width="55px" MaxLength="10" ID="txtAZBudget" Text='<%# Bind("AZBudget") %>' runat="server" />
</ItemTemplate>
<FooterTemplate>
<asp:Label runat="server" id="AZTotal_Label" Text="testing" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="AZ Budget" SortExpression="Name" ItemStyle-HorizontalAlign=
<HeaderStyle HorizontalAlign="Left"></H
<ItemTemplate>
<asp:TextBox width="55px" MaxLength="10" ID="txtAZBudget" Text='<%# Bind("AZBudget") %>' runat="server" />
</ItemTemplate>
<FooterTemplate>
<asp:Label runat="server" id="AZTotal_Label" Text="testing" />
</FooterTemplate>
</asp:TemplateField>
Okay so it is now in the right place on the grid but still not showing up?
If you put a breakpoint on this line
AZBudgetTotal += Convert.ToDecimal(itemTota l)
Does AZBudgetTotal get incremented?
Also try change
AZTotal.Text = AZBudgetTotal.ToString("c0 ")
to
AZTotal.Text = AZBudgetTotal.ToString("c: 0")
If you put a breakpoint on this line
AZBudgetTotal += Convert.ToDecimal(itemTota
Does AZBudgetTotal get incremented?
Also try change
AZTotal.Text = AZBudgetTotal.ToString("c0
to
AZTotal.Text = AZBudgetTotal.ToString("c:
ASKER
If I put a stop point at AZBudgetTotal += Convert.ToDecimal(itemTota l), how can I see the value behind it? I mouse over it once it gets there but don't see a thing except for it to show "Public AZBudgetTotal As Integer = 0"
ASKER
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceExcept ion: Object reference not set to an instance of an object.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Here's my entire code-behind: http://www.webfound.net/codebehind.txt
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceExcept
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Here's my entire code-behind: http://www.webfound.net/codebehind.txt
ASKER
I think i screwed up the update function when I tried putting this line in there:
Dim gv_dashboard As GridView
because it didn't understand what gv_dahsboard was when I created the function
Sub gv_dashboard_RowCreated()
for example.
Dim gv_dashboard As GridView
because it didn't understand what gv_dahsboard was when I created the function
Sub gv_dashboard_RowCreated()
for example.
Yeah you should not need this
Dim gv_dashboard As GridView
Also remember to add
ShowFooter="True"
To your GridView HTML declaration. The easiest way to create the events is to click on your datagrid in Design Time, select properties, click on the lightning bolt and then choose them from there.
Dim gv_dashboard As GridView
Also remember to add
ShowFooter="True"
To your GridView HTML declaration. The easiest way to create the events is to click on your datagrid in Design Time, select properties, click on the lightning bolt and then choose them from there.
ASKER
well, now I'm baffled, wtih the link I gave you to my entire code, without the extra Subs, my UPdate Sub was working fine. Now it cannot recognize my griview name of gv_dashboard for some odd reason.
>> Now it cannot recognize my griview name of gv_dashboard for some odd reason.
Check the designer file to make sure the control declaration is still there and has the correct name....should be something like:
Protected WithEvents gv_dashboard as System.Web.UI...
Along the same lines as what you're trying to do:
http://msconline.maconstate.edu/tutorials/ASPNET2/ASPNET07/aspnet07-05.aspx
I don't have a snippet to post right now...but you can also accomplish footer totals using *only* the RowDatabound of the gridview at runtime...let me know if you want me to dig it up....
st
Check the designer file to make sure the control declaration is still there and has the correct name....should be something like:
Protected WithEvents gv_dashboard as System.Web.UI...
Along the same lines as what you're trying to do:
http://msconline.maconstate.edu/tutorials/ASPNET2/ASPNET07/aspnet07-05.aspx
I don't have a snippet to post right now...but you can also accomplish footer totals using *only* the RowDatabound of the gridview at runtime...let me know if you want me to dig it up....
st
ASKER
yea, if you can dig it up thanks, if it takes a long time don't worry about it. Thanks, yea, I was checking the codegen file and it wasn't in there...
ASKER
what is strange to me is how it disappeared!
ASKER
thanks, I looked back a few days ago at a backed up designer file and it was there. I'll just put it back in...strange...
Protected WithEvents gv_dashboard As System.Web.UI.WebControls. GridView
Protected WithEvents gv_dashboard As System.Web.UI.WebControls.
ASKER
Ok, back to why it's not summing. I'm assuming the array of controls on an aspx page starts with 0
ASKER
Ok, first question. I still do not see how this is summing anything
' Create a variable to store the order total.
Public AZBudgetTotal As Integer = 0
Sub gv_dashboard_RowCreated(By Val sender As Object, ByVal e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.Footer Then
' Get the AZTotal_Label Label control in the footer row.
Dim AZTotal As Label = CType(e.Row.FindControl("A ZTotal_Lab el"), Label)
' Display the grand total of the AZBudget Column formatted as currency.
If (Not AZTotal Is Nothing) Then
AZTotal.Text = AZBudgetTotal.ToString("c: 0")
End If
End If
End Sub
Sub gv_dashboard_RowDataBound( ByVal sender As Object, ByVal e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
' Get the cell that contains the item total.
Dim cell As TableCell = e.Row.Cells(1)
' Get the DataBoundLiteralControl control that contains the
' data bound value.
Dim boundControl As DataBoundLiteralControl = CType(cell.Controls(1), DataBoundLiteralControl)
' Remove the '$' character so that the type converter works properly.
Dim itemTotal As String = boundControl.Text.Replace( "$", "")
' Add the total for an item (row) to the order total.
AZBudgetTotal += Convert.ToDecimal(itemTota l)
End If
End Sub
Second question
I don't think this is right (Dim cell As TableCell = e.Row.Cells(1)). This tells me it's trying to grab the total field...my label which I assume would be 2 in the array of items on my page since the footerfield is third in my gridview
' Create a variable to store the order total.
Public AZBudgetTotal As Integer = 0
Sub gv_dashboard_RowCreated(By
If e.Row.RowType = DataControlRowType.Footer Then
' Get the AZTotal_Label Label control in the footer row.
Dim AZTotal As Label = CType(e.Row.FindControl("A
' Display the grand total of the AZBudget Column formatted as currency.
If (Not AZTotal Is Nothing) Then
AZTotal.Text = AZBudgetTotal.ToString("c:
End If
End If
End Sub
Sub gv_dashboard_RowDataBound(
If e.Row.RowType = DataControlRowType.DataRow
' Get the cell that contains the item total.
Dim cell As TableCell = e.Row.Cells(1)
' Get the DataBoundLiteralControl control that contains the
' data bound value.
Dim boundControl As DataBoundLiteralControl = CType(cell.Controls(1), DataBoundLiteralControl)
' Remove the '$' character so that the type converter works properly.
Dim itemTotal As String = boundControl.Text.Replace(
' Add the total for an item (row) to the order total.
AZBudgetTotal += Convert.ToDecimal(itemTota
End If
End Sub
Second question
I don't think this is right (Dim cell As TableCell = e.Row.Cells(1)). This tells me it's trying to grab the total field...my label which I assume would be 2 in the array of items on my page since the footerfield is third in my gridview
ASKER
Looks like the index of the array is based on the DataSource. In this case then, I don't know what to put for this
Dim cell As TableCell = e.Row.Cells(1)
since the label, which reprents the total value eventually isn't from the datasource...so which index would I have to use for this?
http://scoregasm.blogspot.com/2006/02/aspnet-adding-total-to-gridview.html
A few notes. First, I find it better to index the DataRowView by the column label over the index. The index is based on the DataSource, not the order of the columns in the GridView, so it can be confusing.
Dim cell As TableCell = e.Row.Cells(1)
since the label, which reprents the total value eventually isn't from the datasource...so which index would I have to use for this?
http://scoregasm.blogspot.com/2006/02/aspnet-adding-total-to-gridview.html
A few notes. First, I find it better to index the DataRowView by the column label over the index. The index is based on the DataSource, not the order of the columns in the GridView, so it can be confusing.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I found a better way to do this using this article: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/GridViewEx09.asp
So I changed my DataGrid to:
<asp:GridView
ID="gv_dashboard"
runat="server"
AutoGenerateColumns="False "
DataSourceID="ds_dashboard "
CellPadding="4"
ForeColor="#333333"
ShowFooter="True"
GridLines="None"
CssClass="FormatFont">
<Columns>
<asp:TemplateField HeaderText="Cust #" SortExpression="CustomerID ">
<HeaderStyle HorizontalAlign="center">< /HeaderSty le>
<ItemTemplate>
<asp:Label runat="server" id="lblCustomerID" Text='<%# Bind("Customer") %>' />
</ItemTemplate>
<FooterTemplate>
<asp:Label runat="server" id="Totals_Label" Text="Totals:" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="AZ Budget" SortExpression="Name" ItemStyle-HorizontalAlign= "Center">
<HeaderStyle HorizontalAlign="Left"></H eaderStyle >
<ItemTemplate>
<asp:TextBox width="55px" MaxLength="10" ID="txtAZBudget" Text='<%# Bind("AZBudget") %>' runat="server" />
</ItemTemplate>
<FooterTemplate>
<asp:Label runat="server" id="AZTotal_Label" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="IL Budget" SortExpression="Name" ItemStyle-HorizontalAlign= "Center">
<HeaderStyle HorizontalAlign="Left"></H eaderStyle >
<ItemTemplate>
<asp:TextBox width="55px" MaxLength="10" ID="txtILBudget" Text='<%# Bind("ILBudget") %>' runat="server" />
</ItemTemplate>
<FooterTemplate>
<asp:Label runat="server" id="ILTotal_Label" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="AZ" SortExpression="Name" ItemStyle-HorizontalAlign= "Center">
<HeaderStyle HorizontalAlign="center">< /HeaderSty le>
<ItemTemplate>
<asp:checkbox runat="server" Id="chbx_Arizona" Checked='<%# Bind("Arizona") %>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="IL" SortExpression="Name" ItemStyle-HorizontalAlign= "Center">
<HeaderStyle HorizontalAlign="center">< /HeaderSty le>
<ItemTemplate>
<asp:checkbox runat="server" Id="chbx_Illinois" Checked='<%# Bind("Illinois") %>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Current Month Collections" SortExpression="Name" ItemStyle-HorizontalAlign= "Center">
<HeaderStyle HorizontalAlign="center">< /HeaderSty le>
<ItemTemplate>
<asp:checkbox runat="server" Id="chbx_CurrentMonthColle ctions" Checked='<%# Bind("CurrentMonthCollecti ons") %>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Revenue By Month" SortExpression="Name" ItemStyle-HorizontalAlign= "Center">
<HeaderStyle HorizontalAlign="center">< /HeaderSty le>
<ItemTemplate>
<asp:checkbox runat="server" Id="chbx_RevenueByMonth" Checked='<%# Bind("RevenueByMonth") %>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="PDCs & CCS Monthly" SortExpression="Name" ItemStyle-HorizontalAlign= "Center">
<HeaderStyle HorizontalAlign="center">< /HeaderSty le>
<ItemTemplate>
<asp:checkbox runat="server" Id="chbx_PDCsCCsMonthly" Checked='<%# Bind("PDCsCCsMonthly") %>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Revenue By Client" SortExpression="Name" ItemStyle-HorizontalAlign= "Center">
<HeaderStyle HorizontalAlign="center">< /HeaderSty le>
<ItemTemplate>
<asp:checkbox runat="server" Id="chbx_RevenueByClient" Checked='<%# Bind("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>
and my code-behind to:
Dim AZBudgetTotal As Integer = 0
Dim ILBudgetTotal As Integer = 0
Sub gv_dashboard_RowDataBound( ByVal sender As Object, ByVal e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
' add the UnitPrice and QuantityTotal to the running total variables
AZBudgetTotal += Convert.ToDecimal(DataBind er.Eval(e. Row.DataIt em, "AZBudget"))
ILBudgetTotal += Convert.ToInt32(DataBinder .Eval(e.Ro w.DataItem , "ILBudget"))
ElseIf e.Row.RowType = DataControlRowType.Footer Then
e.Row.Cells(1).Text = "Totals:"
' for the Footer, display the running totals
e.Row.Cells(2).Text = AZBudgetTotal.ToString("c: 0")
e.Row.Cells(3).Text = ILBudgetTotal.ToString("c: 0")
e.Row.Cells(2).HorizontalA lign = HorizontalAlign.Right
e.Row.Cells(3).HorizontalA lign = HorizontalAlign.Right
e.Row.Font.Bold = True
End If
End Sub
So I changed my DataGrid to:
<asp:GridView
ID="gv_dashboard"
runat="server"
AutoGenerateColumns="False
DataSourceID="ds_dashboard
CellPadding="4"
ForeColor="#333333"
ShowFooter="True"
GridLines="None"
CssClass="FormatFont">
<Columns>
<asp:TemplateField HeaderText="Cust #" SortExpression="CustomerID
<HeaderStyle HorizontalAlign="center"><
<ItemTemplate>
<asp:Label runat="server" id="lblCustomerID" Text='<%# Bind("Customer") %>' />
</ItemTemplate>
<FooterTemplate>
<asp:Label runat="server" id="Totals_Label" Text="Totals:" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="AZ Budget" SortExpression="Name" ItemStyle-HorizontalAlign=
<HeaderStyle HorizontalAlign="Left"></H
<ItemTemplate>
<asp:TextBox width="55px" MaxLength="10" ID="txtAZBudget" Text='<%# Bind("AZBudget") %>' runat="server" />
</ItemTemplate>
<FooterTemplate>
<asp:Label runat="server" id="AZTotal_Label" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="IL Budget" SortExpression="Name" ItemStyle-HorizontalAlign=
<HeaderStyle HorizontalAlign="Left"></H
<ItemTemplate>
<asp:TextBox width="55px" MaxLength="10" ID="txtILBudget" Text='<%# Bind("ILBudget") %>' runat="server" />
</ItemTemplate>
<FooterTemplate>
<asp:Label runat="server" id="ILTotal_Label" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="AZ" SortExpression="Name" ItemStyle-HorizontalAlign=
<HeaderStyle HorizontalAlign="center"><
<ItemTemplate>
<asp:checkbox runat="server" Id="chbx_Arizona" Checked='<%# Bind("Arizona") %>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="IL" SortExpression="Name" ItemStyle-HorizontalAlign=
<HeaderStyle HorizontalAlign="center"><
<ItemTemplate>
<asp:checkbox runat="server" Id="chbx_Illinois" Checked='<%# Bind("Illinois") %>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Current Month Collections" SortExpression="Name" ItemStyle-HorizontalAlign=
<HeaderStyle HorizontalAlign="center"><
<ItemTemplate>
<asp:checkbox runat="server" Id="chbx_CurrentMonthColle
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Revenue By Month" SortExpression="Name" ItemStyle-HorizontalAlign=
<HeaderStyle HorizontalAlign="center"><
<ItemTemplate>
<asp:checkbox runat="server" Id="chbx_RevenueByMonth" Checked='<%# Bind("RevenueByMonth") %>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="PDCs & CCS Monthly" SortExpression="Name" ItemStyle-HorizontalAlign=
<HeaderStyle HorizontalAlign="center"><
<ItemTemplate>
<asp:checkbox runat="server" Id="chbx_PDCsCCsMonthly" Checked='<%# Bind("PDCsCCsMonthly") %>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Revenue By Client" SortExpression="Name" ItemStyle-HorizontalAlign=
<HeaderStyle HorizontalAlign="center"><
<ItemTemplate>
<asp:checkbox runat="server" Id="chbx_RevenueByClient" Checked='<%# Bind("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>
and my code-behind to:
Dim AZBudgetTotal As Integer = 0
Dim ILBudgetTotal As Integer = 0
Sub gv_dashboard_RowDataBound(
If e.Row.RowType = DataControlRowType.DataRow
' add the UnitPrice and QuantityTotal to the running total variables
AZBudgetTotal += Convert.ToDecimal(DataBind
ILBudgetTotal += Convert.ToInt32(DataBinder
ElseIf e.Row.RowType = DataControlRowType.Footer Then
e.Row.Cells(1).Text = "Totals:"
' for the Footer, display the running totals
e.Row.Cells(2).Text = AZBudgetTotal.ToString("c:
e.Row.Cells(3).Text = ILBudgetTotal.ToString("c:
e.Row.Cells(2).HorizontalA
e.Row.Cells(3).HorizontalA
e.Row.Font.Bold = True
End If
End Sub
lol...your last post was the code I was going to try to dig up... =0D
ASKER
Weird. I first changed my Total_Label by taking out the Text= portion since the Sub will populate that for me. But when my form is rendered, no text is rendered for Totals_Label nor any totals for the other 2 footer labels:
<asp:GridView
ID="gv_dashboard"
runat="server"
AutoGenerateColumns="False "
DataSourceID="ds_dashboard "
CellPadding="4"
ForeColor="#333333"
ShowFooter="True"
GridLines="None"
CssClass="FormatFont">
<Columns>
<asp:TemplateField HeaderText="Cust #" SortExpression="CustomerID ">
<HeaderStyle HorizontalAlign="center">< /HeaderSty le>
<ItemTemplate>
<asp:Label runat="server" id="lblCustomerID" Text='<%# Bind("Customer") %>' />
</ItemTemplate>
<FooterTemplate>
<asp:Label runat="server" id="Totals_Label" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="AZ Budget" SortExpression="Name" ItemStyle-HorizontalAlign= "Center">
<HeaderStyle HorizontalAlign="Left"></H eaderStyle >
<ItemTemplate>
<asp:TextBox width="55px" MaxLength="10" ID="txtAZBudget" Text='<%# Bind("AZBudget") %>' runat="server" />
</ItemTemplate>
<FooterTemplate>
<asp:Label runat="server" id="AZTotal_Label" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="IL Budget" SortExpression="Name" ItemStyle-HorizontalAlign= "Center">
<HeaderStyle HorizontalAlign="Left"></H eaderStyle >
<ItemTemplate>
<asp:TextBox width="55px" MaxLength="10" ID="txtILBudget" Text='<%# Bind("ILBudget") %>' runat="server" />
</ItemTemplate>
<FooterTemplate>
<asp:Label runat="server" id="ILTotal_Label" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="AZ" SortExpression="Name" ItemStyle-HorizontalAlign= "Center">
<HeaderStyle HorizontalAlign="center">< /HeaderSty le>
<ItemTemplate>
<asp:checkbox runat="server" Id="chbx_Arizona" Checked='<%# Bind("Arizona") %>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="IL" SortExpression="Name" ItemStyle-HorizontalAlign= "Center">
<HeaderStyle HorizontalAlign="center">< /HeaderSty le>
<ItemTemplate>
<asp:checkbox runat="server" Id="chbx_Illinois" Checked='<%# Bind("Illinois") %>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Current Month Collections" SortExpression="Name" ItemStyle-HorizontalAlign= "Center">
<HeaderStyle HorizontalAlign="center">< /HeaderSty le>
<ItemTemplate>
<asp:checkbox runat="server" Id="chbx_CurrentMonthColle ctions" Checked='<%# Bind("CurrentMonthCollecti ons") %>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Revenue By Month" SortExpression="Name" ItemStyle-HorizontalAlign= "Center">
<HeaderStyle HorizontalAlign="center">< /HeaderSty le>
<ItemTemplate>
<asp:checkbox runat="server" Id="chbx_RevenueByMonth" Checked='<%# Bind("RevenueByMonth") %>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="PDCs & CCS Monthly" SortExpression="Name" ItemStyle-HorizontalAlign= "Center">
<HeaderStyle HorizontalAlign="center">< /HeaderSty le>
<ItemTemplate>
<asp:checkbox runat="server" Id="chbx_PDCsCCsMonthly" Checked='<%# Bind("PDCsCCsMonthly") %>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Revenue By Client" SortExpression="Name" ItemStyle-HorizontalAlign= "Center">
<HeaderStyle HorizontalAlign="center">< /HeaderSty le>
<ItemTemplate>
<asp:checkbox runat="server" Id="chbx_RevenueByClient" Checked='<%# Bind("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>
Code-behind:
----------------
Dim AZBudgetTotal As Integer = 0
Dim ILBudgetTotal As Integer = 0
Sub gv_dashboard_RowDataBound( ByVal sender As Object, ByVal e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
' add the UnitPrice and QuantityTotal to the running total variables
AZBudgetTotal += Convert.ToDecimal(DataBind er.Eval(e. Row.DataIt em, "AZBudget"))
ILBudgetTotal += Convert.ToInt32(DataBinder .Eval(e.Ro w.DataItem , "ILBudget"))
ElseIf e.Row.RowType = DataControlRowType.Footer Then
e.Row.Cells(0).Text = "Totals:"
' for the Footer, display the running totals
e.Row.Cells(1).Text = AZBudgetTotal.ToString("c: 0")
e.Row.Cells(2).Text = ILBudgetTotal.ToString("c: 0")
e.Row.Cells(1).HorizontalA lign = HorizontalAlign.Right
e.Row.Cells(2).HorizontalA lign = HorizontalAlign.Right
e.Row.Font.Bold = True
End If
End Sub
<asp:GridView
ID="gv_dashboard"
runat="server"
AutoGenerateColumns="False
DataSourceID="ds_dashboard
CellPadding="4"
ForeColor="#333333"
ShowFooter="True"
GridLines="None"
CssClass="FormatFont">
<Columns>
<asp:TemplateField HeaderText="Cust #" SortExpression="CustomerID
<HeaderStyle HorizontalAlign="center"><
<ItemTemplate>
<asp:Label runat="server" id="lblCustomerID" Text='<%# Bind("Customer") %>' />
</ItemTemplate>
<FooterTemplate>
<asp:Label runat="server" id="Totals_Label" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="AZ Budget" SortExpression="Name" ItemStyle-HorizontalAlign=
<HeaderStyle HorizontalAlign="Left"></H
<ItemTemplate>
<asp:TextBox width="55px" MaxLength="10" ID="txtAZBudget" Text='<%# Bind("AZBudget") %>' runat="server" />
</ItemTemplate>
<FooterTemplate>
<asp:Label runat="server" id="AZTotal_Label" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="IL Budget" SortExpression="Name" ItemStyle-HorizontalAlign=
<HeaderStyle HorizontalAlign="Left"></H
<ItemTemplate>
<asp:TextBox width="55px" MaxLength="10" ID="txtILBudget" Text='<%# Bind("ILBudget") %>' runat="server" />
</ItemTemplate>
<FooterTemplate>
<asp:Label runat="server" id="ILTotal_Label" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="AZ" SortExpression="Name" ItemStyle-HorizontalAlign=
<HeaderStyle HorizontalAlign="center"><
<ItemTemplate>
<asp:checkbox runat="server" Id="chbx_Arizona" Checked='<%# Bind("Arizona") %>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="IL" SortExpression="Name" ItemStyle-HorizontalAlign=
<HeaderStyle HorizontalAlign="center"><
<ItemTemplate>
<asp:checkbox runat="server" Id="chbx_Illinois" Checked='<%# Bind("Illinois") %>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Current Month Collections" SortExpression="Name" ItemStyle-HorizontalAlign=
<HeaderStyle HorizontalAlign="center"><
<ItemTemplate>
<asp:checkbox runat="server" Id="chbx_CurrentMonthColle
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Revenue By Month" SortExpression="Name" ItemStyle-HorizontalAlign=
<HeaderStyle HorizontalAlign="center"><
<ItemTemplate>
<asp:checkbox runat="server" Id="chbx_RevenueByMonth" Checked='<%# Bind("RevenueByMonth") %>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="PDCs & CCS Monthly" SortExpression="Name" ItemStyle-HorizontalAlign=
<HeaderStyle HorizontalAlign="center"><
<ItemTemplate>
<asp:checkbox runat="server" Id="chbx_PDCsCCsMonthly" Checked='<%# Bind("PDCsCCsMonthly") %>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Revenue By Client" SortExpression="Name" ItemStyle-HorizontalAlign=
<HeaderStyle HorizontalAlign="center"><
<ItemTemplate>
<asp:checkbox runat="server" Id="chbx_RevenueByClient" Checked='<%# Bind("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>
Code-behind:
----------------
Dim AZBudgetTotal As Integer = 0
Dim ILBudgetTotal As Integer = 0
Sub gv_dashboard_RowDataBound(
If e.Row.RowType = DataControlRowType.DataRow
' add the UnitPrice and QuantityTotal to the running total variables
AZBudgetTotal += Convert.ToDecimal(DataBind
ILBudgetTotal += Convert.ToInt32(DataBinder
ElseIf e.Row.RowType = DataControlRowType.Footer Then
e.Row.Cells(0).Text = "Totals:"
' for the Footer, display the running totals
e.Row.Cells(1).Text = AZBudgetTotal.ToString("c:
e.Row.Cells(2).Text = ILBudgetTotal.ToString("c:
e.Row.Cells(1).HorizontalA
e.Row.Cells(2).HorizontalA
e.Row.Font.Bold = True
End If
End Sub
ASKER
samtran0331. sweet! yea, I can't believe it's taking me half a day to figure out how to add totals to my gridview. Oh well, live and learn...that's .NET for you.
Any reason why you think nothing is being rendered here to the lables? I think I have everything right in my Sub so far as I can see...
Any reason why you think nothing is being rendered here to the lables? I think I have everything right in my Sub so far as I can see...
ASKER
what the hell is up with Opera anyway, when I paste my URL, it never loads, and stalls...anyway, back to IE I guess.
ps...
Although it's a pretty simple technique...it can be quite powerful to your client...like doing averages...or using the value to change the cell or text color...like if AZBudgetTotal > 50000 for the current row, you can set the column to bold or something...
Although it's a pretty simple technique...it can be quite powerful to your client...like doing averages...or using the value to change the cell or text color...like if AZBudgetTotal > 50000 for the current row, you can set the column to bold or something...
ASKER
yea, just figuring out why the hell it isn't showing any text in my labels. How is this Sub invoked? do I need to invoke it?
you shouldn't need labels in the footer...you're writing the values right into the cell when you do "e.Row.Cells(*).Text"
if you use labels...you'd need to get the label either by FindControl or referencing the control directly before you can set its text
if you use labels...you'd need to get the label either by FindControl or referencing the control directly before you can set its text
ASKER
so any clues as to why it's not populating my labels...all 3 are not showing a thing in my footerfields:
Here's my latest code:
http://www.webfound.net/index_.txt
http://www.webfound.net/codebehind_gridview.txt
Here's my latest code:
http://www.webfound.net/index_.txt
http://www.webfound.net/codebehind_gridview.txt
ASKER
I don't see why it's not populating the labels
ASKER
oh, I see...let me take the lables out...
...I guess I didn't really answer your last 2 questions:
> How is this Sub invoked? do I need to invoke it?
Any time you bind your grid, the gv_dashboard_RowDataBound will be invoked.
so, no, you don't need to do anything else beside bind the grid to fire off the gv_dashboard_RowDataBound
> How is this Sub invoked? do I need to invoke it?
Any time you bind your grid, the gv_dashboard_RowDataBound will be invoked.
so, no, you don't need to do anything else beside bind the grid to fire off the gv_dashboard_RowDataBound
ASKER
Ok but if I take the lables out, basically I'll have 3 of these...then I assume it's referencing them by index then at that point which is 0, 1, and 2 starting from top down?
<HeaderStyle HorizontalAlign="center">< /HeaderSty le>
<ItemTemplate>
<asp:Label runat="server" id="lblCustomerID" Text='<%# Bind("Customer") %>' />
</ItemTemplate>
<FooterTemplate>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="AZ Budget" SortExpression="Name" ItemStyle-HorizontalAlign= "Center">
<HeaderStyle HorizontalAlign="Left"></H eaderStyle >
<ItemTemplate>
<asp:TextBox width="55px" MaxLength="10" ID="txtAZBudget" Text='<%# Bind("AZBudget") %>' runat="server" />
</ItemTemplate>
<FooterTemplate>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="IL Budget" SortExpression="Name" ItemStyle-HorizontalAlign= "Center">
<HeaderStyle HorizontalAlign="Left"></H eaderStyle >
<ItemTemplate>
<asp:TextBox width="55px" MaxLength="10" ID="txtILBudget" Text='<%# Bind("ILBudget") %>' runat="server" />
</ItemTemplate>
<FooterTemplate>
</FooterTemplate>
</asp:TemplateField>
<HeaderStyle HorizontalAlign="center"><
<ItemTemplate>
<asp:Label runat="server" id="lblCustomerID" Text='<%# Bind("Customer") %>' />
</ItemTemplate>
<FooterTemplate>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="AZ Budget" SortExpression="Name" ItemStyle-HorizontalAlign=
<HeaderStyle HorizontalAlign="Left"></H
<ItemTemplate>
<asp:TextBox width="55px" MaxLength="10" ID="txtAZBudget" Text='<%# Bind("AZBudget") %>' runat="server" />
</ItemTemplate>
<FooterTemplate>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="IL Budget" SortExpression="Name" ItemStyle-HorizontalAlign=
<HeaderStyle HorizontalAlign="Left"></H
<ItemTemplate>
<asp:TextBox width="55px" MaxLength="10" ID="txtILBudget" Text='<%# Bind("ILBudget") %>' runat="server" />
</ItemTemplate>
<FooterTemplate>
</FooterTemplate>
</asp:TemplateField>
ASKER
this is driving me batty. I took out the labels in my GridView as you see above. All other code is the same as I posted via those 2 links. Why isn't it rendering anytying in those FooterTemplates?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
so you didn't even use footertemplate...why?
ASKER
AHHHHHHHHHHHH, I was missing Handles gv_dashboard.RowDataBound
What exactly is that doing?
What exactly is that doing?
ASKER
it's working! thanks a lot!
>>What exactly is that doing?
If you're using codebehind...the "handles" part is what wires up the subroutine to the datagrid
you could have just as well named the sub something else and left off the Handle like:
Private Sub keepRunningSum(ByVal sender As Object, ByVal e As System.Web.UI.WebControls. GridViewRo wEventArgs )
Try
If e.Row.RowType = DataControlRowType.DataRow Then
dblAD1 += Convert.ToDecimal(DataBind er.Eval(e. Row.DataIt em, "sumProd"))
....etc....
End Sub
And then in your datagrid/gridview on the aspx page set the tag:
<asp:grdiview OnRowDatabound="keepRunnin gSum"..... > etc....
If you're using codebehind...the "handles" part is what wires up the subroutine to the datagrid
you could have just as well named the sub something else and left off the Handle like:
Private Sub keepRunningSum(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.
Try
If e.Row.RowType = DataControlRowType.DataRow
dblAD1 += Convert.ToDecimal(DataBind
....etc....
End Sub
And then in your datagrid/gridview on the aspx page set the tag:
<asp:grdiview OnRowDatabound="keepRunnin
ASKER
http://aspalliance.com/782
so far, I've done this:
......
<FooterTemplate>
<%# GetAZTotal().ToString("N2"
</FooterTemplate>
</Columns>
and in my code-behind:
Dim TotalAZBudget As Integer
Function GetAZBudget(ByVal AZBudget As Integer) As Integer
TotalAZBudget += AZBudget
Return AZBudget
End Function
Function GetAZBudgetTotal() As Integer
Return TotalAZBudget
End Function
Error I'm getting:
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Parser Error Message: System.Web.UI.WebControls.
Source Error:
Line 105: </ItemTemplate>
Line 106: </asp:TemplateField>
Line 107: <FooterTemplate>
Line 108: <%# GetAZTotal().ToString("N2"
Line 109: </FooterTemplate>