Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Repeater Footer

Status
Not open for further replies.

arpan

Programmer
Oct 16, 2002
336
IN
I am retrieving & displaying records from a SQL Server DB table in a Repeater. Now I want to display the sum of all the rows of 2 columns in the FooterTemplate of the Repeater. This is what I have done:

<script language=&quot;VB&quot; runat=&quot;server&quot;>
Sub Page_Load(obj As Object,ea As EventArgs)
Dim iBasicTotal As Double=0
Dim iPFTotal As Double=0

objDapter=New SQLDataAdapter(&quot;SELECT blah...blah..&quot;,objConn)
objDS=new DataSet()
objDapter.Fill(objDS,&quot;PFRegister&quot;)
dTable=objDS.Tables(&quot;PFRegister&quot;)

For Each dRow In dTable.Rows
iBasicTotal=iBasicTotal+CType(dRow(&quot;Basic&quot;),Double)
iPFTotal=iPFTotal+CType(dRow(&quot;PF&quot;),Double)
Next

myRep.DataSource=objDS.Tables(&quot;PFRegister&quot;).DefaultView
myRep.DataBind()
End Sub
</script>
............
<asp:Repeater id=&quot;myRep&quot; OnItemDataBound=&quot;AttachFooter&quot; runat=&quot;server&quot;>
<HeaderTemplate>
<table border=2>
<!-- Display The Column Headers Here -->
</HeaderTemplate>
<ItemTemplate>
<!-- Display The Records Here -->
</ItemTemplate>
<FooterTemplate>
<tr>
<th colspan=3>TOTAL</th>
<td><asp:Label id=&quot;BasicTotal&quot; runat=&quot;server&quot;/>
<td><asp:Label id=&quot;PFTotal&quot; runat=&quot;server&quot;/>
</tr>
</table>
</FooterTemplate>
</asp:Repeater>

Now my question is how do I pass the 2 totals (iBasicTotal & iPFTotal) from the Page_Load Sub to the Sub AttachFooter (OnItemDataBound event) so that using the ListItemType property in the AttachFooter Sub, I can display the 2 totals in the 2 labels in the FooterTemplate i.e. the AttachFooter Sub will look something like this:

Sub AttachFooter(obj As Object,ea As RepeaterItemEventArgs)
If(ea.Item.ItemType=ListItemType.Footer) Then
CType(ea.Item.FindControl(&quot;basicLabel&quot;),Label).Text=BasicTotal
CType(ea.Item.FindControl(&quot;pfLabel&quot;),Label).Text=PFTotal
End If
End Sub

So how do I pass the values of the 2 variables in the Page_Load Sub, iBasicTotal & iPFTotal, to the AttachFooter Sub?

Thanks,

Arpan
 
Declare the variables with class scope, and place the following in your footer:

<%# getTotal() %>

Then declare the getTotal function in your codebehind with a return type of string (or int, or double, or whatever), grab the value in the function, and return it to the caller
penny1.gif
penny1.gif
 
I couldn't follow exactly what you are trying to suggest. Actually I am a newbie in ASP.NET. What do you mean by &quot;declare the variables in class scope&quot;? How do I do that? Also I am not using any codebehind & wouldn't like to use one. Could you please show me a small example of how do I go about it? Please give it using VB.NET (not C#).

Thanks,

Regards,

Arpan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top