Hi Sck10,
Welcome to ASPNet newsgroup.
From your descrition, you're using the ASP.NET repeater control to display
some records on the page, the datasource contains a price column(decimal?).
So you're wantting to put two labels in the repeater's Footer template so
as to display the Items Count and Total price (sum) of the records in
datasource, yes?
Based on my experience, the most common means to do this is utilizing the
Repeater control's ItemDataBound event. This event will fire during the
databinding of each item in repeater (Header, item/alternateitem/
footer....). So we can just add a <HeaderTemplate> ... into repeater (so
that it will be bound in ItemDataBound event...) and define an member
variable in Page class which can be used to store the Price sum value
during the ItemDataBound event. Then, add this value eachtime the Item or
AlternateItem is bound with data. For example:
"price_sum" is a page's member variable (of decimal type)....
====================
protected void Repeater1_ItemDataBound(object sender,
RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Header)
{
price_sum = 0;
}
else if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
price_sum +=
(decimal)((DataRowView)e.Item.DataItem)["UnitPrice"];
}
else if (e.Item.ItemType == ListItemType.Footer)
{
Label lblCount = e.Item.FindControl("lblItemCount") as Label;
lblCount.Text = "Count: " + Repeater1.Items.Count;
Label lblSum = e.Item.FindControl("lblItemPrice") as Label;
lblSum.Text = "Total Price: " + price_sum;
}
}
=====================
=======repeater template========
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1"
OnDataBinding="Repeater1_DataBinding"
OnItemDataBound="Repeater1_ItemDataBound">
<HeaderTemplate>
<br />
</HeaderTemplate>
<ItemTemplate >
<br /><%# Eval("ProductName") %>, <%# Eval("UnitPrice","{0:C}") %>
</ItemTemplate>
<FooterTemplate >
<hr size="1" width="100%" />
<asp:Label ID="lblItemCount" runat="server" Text=""></asp:Label>
<asp:Label ID="lblItemPrice" runat="server" Text=""></asp:Label>
</FooterTemplate>
</asp:Repeater>
============================
Hope helps. Thanks,
Steven Cheng
Microsoft Online Support
Get Secure!
www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| From: "sck10" <
[email protected]>
| Subject: Repeater control footer summary (asp.net 2 with vb)
| Date: Mon, 28 Nov 2005 16:03:42 -0600
| Lines: 23
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1506
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1506
| Message-ID: <
[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: 189.202.185.135.in-addr.arpa 135.185.202.189
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:361354
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Hello,
|
| I have a repeater that is bound to a SQL Server table. I would like to
| place a summary in the footer for the item count and product cost.
|
| I have two fields. One for the product name and the other for product
| cost.
|
| <%#Container.DataItem("ProductA")%>
| <%#Container.DataItem("PriceA")%>
|
| My question is, how to count the products (ProductA), get the total price
| (sum PriceA) and then place the value in the footer.
|
| Any help with this would be appreciated.
|
| --
| Thanks in advance,
|
| sck10
|
|
|
|