How do I put computed values in 'formview'

C

COHENMARVIN

I have a formview control, with labels arranged in a table. The
labels are bound to fields from a query. But I also want to sum up
the values in the table and put them in a row of totals at the bottom.
What I find is that the labels in the table are not accessible from
the code-behind page.
I'd like to do something like this:
lblTotal.text = cint(lblrow1.text) + cint(lblrow2.text) etc.
But the codebehind doesn't recognize the labels. Maybe thats because
they are within a formview.
Is there any way to compute totals within a formview?
Thanks,
Marvin
 
S

Stan

I have a formview control, with labels arranged in a table.  The
labels are bound to fields from a query.  But I also want to sum up
the values in the table and put them in a row of totals at the bottom.
What I find is that the labels in the table are not accessible from
the code-behind page.
I'd like to do something like this:
lblTotal.text = cint(lblrow1.text) + cint(lblrow2.text) etc.
But the codebehind doesn't recognize the labels.  Maybe thats because
they are within a formview.
Is there any way to compute totals within a formview?
Thanks,
Marvin

That would be one way of doing it - you could put code in the
RowDatabound event handler and access the content of the labels with
e.item.FindControl()

There are easier and more efficient ways to do it though!

For example

(1) Create an expression for the databinding of the results label
like this

<asp:label ... text='<%# Eval(Value1) + Eval(Value2) ... %>' ...

(2) do it in the query itself -

Select Value1, Value2, Value1 + Value2 as Value3 ...

then bind the label destined to display the result to the column named
Value3

HTH
 

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,756
Messages
2,569,533
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top