Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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

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

code-behind:

litTotal.Text = GetTheSum();

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top