Wrox Programmer Forums
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 23rd, 2004, 01:31 PM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 218
Thanks: 0
Thanked 0 Times in 0 Posts
Default Running Total in DataList

Hello again-

One of the columns in my datalist contains an integer value. There are times in my list that I need to show the total for a number of rows.

For example,

1
2
2
--
5

2
1
3
--
6

and so on.


Here's my code:
Code:
Public CaseTotal As Integer = 0
.
.
Public Sub dlItemDataBound(ByVal sender As Object, ByVal e As DataListItemEventArgs)
        If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
            Dim CenterLabel, lblSep, Cases, Total As Label
            Select Case e.Item.ItemType
                Case ListItemType.Item
                    CenterLabel = CType(e.Item.FindControl("lblCenter"), Label)
                    lblSep = CType(e.Item.FindControl("lblSeparate"), Label)
                    Cases = CType(e.Item.FindControl("lblCases"), Label)
                    Total = CType(e.Item.FindControl("lblTotal"), Label)
                Case ListItemType.AlternatingItem
                    CenterLabel = CType(e.Item.FindControl("lblAltCenter"), Label)
                    lblSep = CType(e.Item.FindControl("lblAltSeparate"), Label)
                    Cases = CType(e.Item.FindControl("lblAltCases"), Label)
                    Total = CType(e.Item.FindControl("lblAltTotal"), Label)
            End Select

            CaseTotal += CInt(Cases.Text)
            Total.Text = "Total:   " & FormatNumber(CaseTotal, 0, , , TriState.True)

            If curCenter = CenterLabel.Text Then
                CenterLabel.Visible = False
                lblSep.Visible = False
                Total.Visible = False
            Else
                'new Center
                CenterLabel.Visible = True
                lblSep.Visible = True
                Total.Visible = True
                CaseTotal = 0
            End If
            curCenter = CenterLabel.Text
        End If
    End Sub
The idea is to total up the value in lblCases to display when there is a new center.
The line
Code:
CaseTotal += CInt(Cases.Text)
gives an error, "InvalidCastException: Cast from string "" to type 'Integer' is not valid." That is, Cases.Text is empty.

What gives?

- - - - - - - - - - - - - - - - - - - - - - -
In God we trust, everything else we test.
 
Old October 25th, 2004, 09:27 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 218
Thanks: 0
Thanked 0 Times in 0 Posts
Default

FYI, I found the problem.

In the datalist, I had the lblCases defined like this:
Code:
<asp:Label id="lblCases" runat="server" CssClass="formlabel">
<%# Databinder.Eval(Container.DataItem,"NumCases")%>
</asp:Label>
When it should have been like this:
Code:
<asp:Label id="lblCases" runat="server" CssClass="formlabel" Text='<%# Databinder.Eval(Container.DataItem,"NumCases")%>'></asp:Label>
- - - - - - - - - - - - - - - - - - - - - - -
In God we trust, everything else we test.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Calculate a running total Neal XSLT 3 March 22nd, 2007 11:16 AM
Using Running total in crystal reports prathap BOOK: Professional Crystal Reports for VS.NET 0 October 17th, 2006 02:37 AM
Running Total jdmorr SQL Language 5 March 9th, 2005 03:28 PM
Running Total Fields edramail Crystal Reports 0 May 17th, 2004 09:22 PM
Running Total on group header scamp Crystal Reports 0 May 3rd, 2004 06:18 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.