Results 1 to 5 of 5

Thread: [RESOLVED] itemdatabound doubles total

Threaded View

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2000
    Location
    Minnesota
    Posts
    830

    [RESOLVED] itemdatabound doubles total

    The framework using is 3.5.

    Situation: I have a page which I call a stored procedure that returns two results. I create a dataset and then from that create two dataviews which one can have multiple records.

    Issue: During the rptInvoice_ItemDataBound of the repeater I am adding the amount value. The problem is it's always double what it should be. If I have one result with a total of $100 it shows $200. If I have two records each with $150 the total shown is $600. It's like its looping twice per row but only showing the row once.

    Any thoughts on why my total is double?

    Here is my code.
    Code:
        Dim cFn As clsFunctions = New clsFunctions
        Dim cEncDec As clsEncryptDecrypt = New clsEncryptDecrypt
    
        Private m_Total As Decimal
    
        Public Property Total() As Decimal
            Get
                Return m_Total
            End Get
            Set(ByVal Value As Decimal)
                m_Total = Value
            End Set
        End Property
    
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            If Not IsPostBack Then
                   '......
                    sbFillPage(ID)
                    lblTotal.Text = Total
            End If
        End Sub
    
        Private Sub sbFillPage(ByVal iPaypalTransactionID As Integer)
            'Get information for receipt page
            Dim dsReceiptInfo As DataSet = cFn.fnGetReceiptInfo(iPaypalTransactionID)
            Dim dvPaypalInfo As DataView = New DataView(dsReceiptInfo.Tables(0))
            Dim dvInvoiceInfo As DataView = New DataView(dsReceiptInfo.Tables(1))
    
            If dvPaypalInfo.Count > 0 Then
                lblOrderNum.Text = iPaypalTransactionID
                lblOrderDateTime.Text = dvPaypalInfo(0)("xxx")
                lblFirstName.Text = dvPaypalInfo(0)("xxx")
                lblLastName.Text = dvPaypalInfo(0)("xxx")
            End If
    
            lblInvoiceCount.Text = dvInvoiceInfo.Count
    
            rptInvoice.DataSource = dvInvoiceInfo
            rptInvoice.DataBind()
    
        End Sub
    
        Protected Sub rptInvoice_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles rptInvoice.ItemDataBound
            If e.Item.ItemType = ListItemType.Header Then
                Total = 0
            End If
    
            If ((e.Item.ItemType = ListItemType.Item) _
                        OrElse (e.Item.ItemType = ListItemType.AlternatingItem)) Then
                Total += CType(e.Item.DataItem, DataRowView)("invoice_amt")
            End If
        End Sub
    HTML Code:
    <asp:Repeater ID="rptInvoice" runat="server" OnItemDataBound="rptInvoice_ItemDataBound">
                <HeaderTemplate><table>
                <tr>
                    <th>Invoice</th>
                    <th>Total</th>
                </tr></HeaderTemplate>
                <ItemTemplate>
                    <tr>
                        <td><%# DataBinder.Eval(Container.DataItem, "invoice_id")%></td>
                        <td><%# Eval("invoice_amt", "{0:C}")%></td>
                    </tr>
                </ItemTemplate>
                <FooterTemplate>
                </table>
                </FooterTemplate>
            </asp:Repeater>
    Last edited by lleemon; Mar 26th, 2011 at 07:25 AM. Reason: resolved

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width