jmurrayhead, thanks for the help, but this what I got. I've created a sql dat source that shows my practice repeater information, heres an image of shown when I compile or run the aspx page:

Now I want to calculate the totals for the Received columns and the Answars column. I tried using the same code I used to calculate the totals in the gridview, but I get an error:
Server Error in '/questionaire' Application.
--------------------------------------------------------------------------------
Operator '=' is not defined for type 'DataRowView' and type 'DataControlRowType'.
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.InvalidCastException: Operator '=' is not defined for type 'DataRowView' and type 'DataControlRowType'.
Source Error:
Line 22: Dim total2 As Decimal = 0
Line 23:
Line 24: If e.Item.DataItem = DataControlRowType.DataRow Then
Line 25: Total += GetUnitPrice(Convert.ToDecimal(DataBinder.Eval(e.I tem.DataItem, "received")))
Line 26: total2 += GetUnitPrice(Convert.ToDecimal(DataBinder.Eval(e.I tem.DataItem, "ansers")))
Source File: C:\Documents and Settings\DPeebles\Desktop\wizard\questionaire\addr owgridview.aspx.vb Line: 24
Here the repeater source code: Aspx page
Code:
<form id="form1" runat="server">
<div>
</div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:peebman %>" SelectCommand="SELECT COUNT(id) AS received, COUNT(cost) AS ansers, product
FROM dbo.product
group by product"></asp:SqlDataSource>
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1">
<HeaderTemplate>
<table border=1>
<tr>
<td><b>Received</b></td>
<td><b>Answars</b></td>
<td><b>Product</b></td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td> <%#DataBinder.Eval(Container.DataItem, "received")%> </td>
<td> <%#DataBinder.Eval(Container.DataItem, "ansers")%> </td>
<td> <%# DataBinder.Eval(Container.DataItem, "product") %> </td>
</tr>
</ItemTemplate>
</asp:Repeater>
</form>
this is my code for aspx.vb page:
Code:
Dim Total As Integer = 0
Protected Sub Repeater1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles Repeater1.ItemDataBound
Dim total2 As Decimal = 0
If e.Item.DataItem = DataControlRowType.DataRow Then
Total += GetUnitPrice(Convert.ToDecimal(DataBinder.Eval(e.Item.DataItem, "received")))
total2 += GetUnitPrice(Convert.ToDecimal(DataBinder.Eval(e.Item.DataItem, "ansers")))
ElseIf e.Item.DataItem = DataControlRowType.Footer Then
e.Item.DataItem.cell(0).text = Total.ToString()
e.Item.DataItem.cell(1).text = total2.ToString()
End If
End Sub
Dim TotalUnitPrice As Decimal = 0.0 '''''CALULATE TOTATS FOR EACH CELL IN GRIDVIEW
Dim TotalUnitPrice2 As Decimal = 0.0
Function GetUnitPrice(ByVal Price As Decimal) As Decimal
TotalUnitPrice += Price
Return Price
End Function
Function GetTotal() As Decimal
Return TotalUnitPrice
End Function
Function GetUnitPrice2(ByVal Price As Decimal) As Decimal
TotalUnitPrice2 += Price
Return Price
End Function
Function GetTotal2() As Decimal
Return TotalUnitPrice2
End Function
End Class
Any thoughts on the error, i know i'm doing this wrong, but I'm not for sure how to get around it. I'm still looking on line, but some of the things I found is a little unclear to me.
Thanks.

Originally Posted by
jmurrayhead
That is one possibility. Another possibility would be to place some labels or whatever you want to use to display the data. Then, in the ItemDataBound event, use these controls as a holding place for the count and just add to the existing value.
Bookmarks