Use a label in a FooterTemplate control? Surely, there must be a way...

G

Groove

I have a typical Repeater that contains a Template (html table). The
repeater / template lists many records and in the footer, I'd like to simply
SUM up the $$ amounts from all the records in the repeater. Easy enough.

So I tried to place a Label control in the footer and fill the Text of the
label from code. I get the label is not declared error. So how can I go
about doing this? I tried writing a helper function in the code-behind file
to get the value to place in the label but can't seem to get it work.

Any ideas? Thanks in advance!

(ASP.NET 2/VB)

<FooterTemplate>
<tr valign="top">
<td colspan="2" align="right" class="ColumnHeader">Total</td>
<td class="ColumnHeader" width="25%"><asp:Label ID="lblTotalCapitalBudgets"
runat="server" Font-Bold="true"
Text="<%#GetTotal(Container.DataItem("ParentRecordID")%>" /></td>
</tr>
</table>
</FooterTemplate>



Protected Function GetTotal(intRecordID As Integer) As String

..typical function to run a SQL Statement to get a SUM..

End Function





Compiler Error Message: BC30451: Name 'lblTotalCapitalBudgets' is not
declared.
 
N

Nathan Sokalski

Well, I haven't seen your entire code, but if you go to your code you should
see a section near the top inside the "Web Form Designer Generated Code"
region where all the Controls on the page are declared. Most (if not all) of
these will look like the following:


Protected WithEvents yourcontrolid As System.Web.UI.WebControls.HyperLink


If Visual Studio didn't add your Label to this list for you, you can add it
yourself, yours would look like the following:


Protected WithEvents lblTotalCapitalBudgets As
System.Web.UI.WebControls.Label


Something else I want to point out to you is that your quotes are mismatched
in the Text attribute. Try changing the Text attribute to look like the
following:


Text='<%#GetTotal(Container.DataItem("ParentRecordID")%>'


Notice that the outer quotes are single quotes (') and the inner quotes are
double quotes ("). It is also a good idea and more efficient to get the sum
using SQL code rather than the ASP.NET code, if you need to know how to do
this let me know and I will be happy to help you. Good Luck!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top