DataItem.Eval inside <FooterTemplate>

  • Thread starter Thread starter tascien
  • Start date Start date
T

tascien

I am just wondering... can footertemplate hold data?

b/c i want to show the sum of my Invoice in footer template. How can i
do that? I could add the sum to the dataset like this:

SumColumn = new DataColumn("SumColumn",Double,"Sum(ItemTotal)")
ds.tables(0).columns.Add(SumColumn)

if i do:

<%#DataBinder.Eval(Container,"DataItem.SumColumn")%> inside the footer
template, i get nothing...

Any help?
 
Hi,

Data could be binded in the footer template. This is possible.

Hope so,

<%# DataBinder.Eval(Container,"DataItem.SumColumn") %> this is wrong. The
right syntax is
<%# DataBinder.Eval(Container.DataItem,"SumColumn") %>
 
The Syntax you suggested above fails to compile:

'DataItem' is not a member of 'System.Web.UI.Control'.

Tascien
 
Hi there,

You need to handle the DataGrid's ItemDataBound event. This event is raised
every time an item is bound to the data source. You can then have a variable
that adds up all the values in this event and display it in the footer by
handling the ItemCreated event. Check the documentation, the arguments of
these events include the item, so you can add a label control to display the
total at the footer.

Good luck!
 
Ahhhhhhhhhh... funny but this one seem to be working...:

<%#Ctype(Container.Parent,Object).DataSource(0)("ID") %>

funny... see below (but it will crash if the invoice contains no
items... ) :

<asp:Repeater id=Repeater2 DataSource='<%# GetSales() %>'
runat="server">

<ItemTemplate>
<%# DataBinder.Eval( Container, "DataItem.ID" ) %>
</ItemTemplate>

<FooterTemplate>
<%# Ctype(Container.Parent,Object).DataSource(0)("Sum") %>
</FooterTemplate>

</asp:Repeater>
 
As a general rule, I suggest you avoid doing runtime data binding. It is
much slower and not a good practice. It is preferable to do it in the
assembly so the code is compiled, fast, and easy to understand.
 
Back
Top