By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,663 Members | 1,638 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,663 IT Pros & Developers. It's quick & easy.

Repeater control footer summary (asp.net 2 with vb)

P: n/a
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

Nov 28 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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" <sc***@online.nospam>
| 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: <uc**************@TK2MSFTNGP12.phx.gbl>
| 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!TK2MSFT NGP12.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
|
|
|
|

Nov 29 '05 #2

P: n/a
This is a c# ItemDataBound event handler I wrote for a similar task.

protected void dgCoding_ItemDataBound (object sender,
System.Web.UI.WebControls.RepeaterItemEventArgs e)
{
System.Web.UI.WebControls.Repeater rep = sender as
System.Web.UI.WebControls.Repeater;

if (e.Item.ItemType == ListItemType.Footer)
{
// count totals
decimal totalFee = 0;
foreach (System.Web.UI.WebControls.RepeaterItem item in
rep.Items)
{
System.Web.UI.HtmlControls.HtmlTableRow row =
item.FindControl ("trCod") as System.Web.UI.HtmlControls.HtmlTableRow;
string fee = row.Cells[6].InnerText;
if (fee != String.Empty)
totalFee += System.Convert.ToDecimal (fee);
}
System.Web.UI.HtmlControls.HtmlTableRow totalRow =
e.Item.FindControl ("trTotal") as System.Web.UI.HtmlControls.HtmlTableRow;
totalRow.Cells[1].InnerText = totalFee.ToString ("f2");
}
}

Eliyahu

"sck10" <sc***@online.nospam> wrote in message
news:uc**************@TK2MSFTNGP12.phx.gbl...
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

Nov 29 '05 #3

P: n/a
Thanks Steve and Eliyahu.
"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:uC**************@TK2MSFTNGP15.phx.gbl...
This is a c# ItemDataBound event handler I wrote for a similar task.

protected void dgCoding_ItemDataBound (object sender,
System.Web.UI.WebControls.RepeaterItemEventArgs e)
{
System.Web.UI.WebControls.Repeater rep = sender as
System.Web.UI.WebControls.Repeater;

if (e.Item.ItemType == ListItemType.Footer)
{
// count totals
decimal totalFee = 0;
foreach (System.Web.UI.WebControls.RepeaterItem item in
rep.Items)
{
System.Web.UI.HtmlControls.HtmlTableRow row =
item.FindControl ("trCod") as System.Web.UI.HtmlControls.HtmlTableRow;
string fee = row.Cells[6].InnerText;
if (fee != String.Empty)
totalFee += System.Convert.ToDecimal (fee);
}
System.Web.UI.HtmlControls.HtmlTableRow totalRow =
e.Item.FindControl ("trTotal") as System.Web.UI.HtmlControls.HtmlTableRow;
totalRow.Cells[1].InnerText = totalFee.ToString ("f2");
}
}

Eliyahu

"sck10" <sc***@online.nospam> wrote in message
news:uc**************@TK2MSFTNGP12.phx.gbl...
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

Nov 29 '05 #4

P: n/a
You're welcome Sck10,

Regards,

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" <sc***@online.nospam>
| References: <uc**************@TK2MSFTNGP12.phx.gbl>
<uC**************@TK2MSFTNGP15.phx.gbl>
| Subject: Re: Repeater control footer summary (asp.net 2 with vb)
| Date: Tue, 29 Nov 2005 08:56:51 -0600
| Lines: 59
| 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: <#S**************@TK2MSFTNGP14.phx.gbl>
| 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!TK2MSFT NGP14.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:361476
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Thanks Steve and Eliyahu.
|
|
| "Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
| news:uC**************@TK2MSFTNGP15.phx.gbl...
| > This is a c# ItemDataBound event handler I wrote for a similar task.
| >
| > protected void dgCoding_ItemDataBound (object sender,
| > System.Web.UI.WebControls.RepeaterItemEventArgs e)
| > {
| > System.Web.UI.WebControls.Repeater rep = sender as
| > System.Web.UI.WebControls.Repeater;
| >
| > if (e.Item.ItemType == ListItemType.Footer)
| > {
| > // count totals
| > decimal totalFee = 0;
| > foreach (System.Web.UI.WebControls.RepeaterItem item in
| > rep.Items)
| > {
| > System.Web.UI.HtmlControls.HtmlTableRow row =
| > item.FindControl ("trCod") as System.Web.UI.HtmlControls.HtmlTableRow;
| > string fee = row.Cells[6].InnerText;
| > if (fee != String.Empty)
| > totalFee += System.Convert.ToDecimal (fee);
| > }
| > System.Web.UI.HtmlControls.HtmlTableRow totalRow =
| > e.Item.FindControl ("trTotal") as
System.Web.UI.HtmlControls.HtmlTableRow;
| > totalRow.Cells[1].InnerText = totalFee.ToString ("f2");
| > }
| > }
| >
| > Eliyahu
| >
| > "sck10" <sc***@online.nospam> wrote in message
| > news:uc**************@TK2MSFTNGP12.phx.gbl...
| > > 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
|
|
|

Nov 30 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.