Results 1 to 5 of 5

Thread: [RESOLVED] itemdatabound doubles total

  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

  2. #2
    Lively Member n3xus's Avatar
    Join Date
    Feb 2007
    Location
    c:\Programme files\
    Posts
    98

    Re: itemdatabound doubles total

    Try 2 things.

    1: Try deleting OnItemDataBound from your repeater.
    2: If first doesn't help try deleting Handles rptInvoice.ItemDataBound From your procedure.


    I'm not sure but it could be that both onItemDataBound in html and Handler event in vb is calling the function resulting in 2 call.
    Last edited by n3xus; Mar 26th, 2011 at 04:51 AM.

  3. #3

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

    Re: itemdatabound doubles total

    n3xus - Thanks. #2 did the trick.

  4. #4
    Lively Member n3xus's Avatar
    Join Date
    Feb 2007
    Location
    c:\Programme files\
    Posts
    98

    Re: [RESOLVED] itemdatabound doubles total

    Thanks for thanking me

  5. #5
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: [RESOLVED] itemdatabound doubles total

    Hello,

    I have seen this issue a couple times, and in all honesty, it is a little annoying, I would have thought that Visual Studio should have been able to pick this up for you?!?

    Gary

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