views:

1853

answers:

5

I'm using the ListView control (ASP.NET 2008) to show a bunch of lines of data, and at the bottom I want some totals. I was initially going to define the header and footer in the LayoutTemplate and get the totals with some local function, i.e. <%#GetTheSum()%>, but it appears that the LayoutTemplate does not process the <%#...%> syntax.

Another thought would be to put a Label in the LayoutTemplate and use FindControl to update it. Not sure if that's possible (will try shortly).

What's the best way to show totals using a ListView?

UPDATE: Solution here.

+1  A: 

Use a literal and set the variable in the code-behind.

<asp:Literal ID="litTotal" runat="server" />

code-behind:

litTotal.Text = GetTheSum();
craigmoliver
A: 

You can't reference the control in the code-behind because it's in the LayoutTemplate. Maybe with FindControl, but I haven't tried that yet.

gfrizzle
+3  A: 

It turns out that FindControl does work:

CType(MyListView.FindControl("litTotal"), Literal).Text = GetTheSum()

I'd still like to know if there might be a better way though.

gfrizzle
in ASP.NET web forms (non-MVC), that's the way.
craigmoliver
A: 

Thanks craigmoliver this helped me to resolve my issues

A: 

Please check this solution http://www.codeproject.com/KB/aspnet/LayoutTemplate%5FDataBind.aspx

Juan