How do I put computed values in 'formview'

  • Thread starter Thread starter COHENMARVIN
  • Start date Start date
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
 
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
 
Back
Top