How do I put computed values in 'formview'

Discussion in 'ASP .Net' started by COHENMARVIN@lycos.com, May 5, 2008.

  1. Guest

    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
     
    , May 5, 2008
    #1
    1. Advertisements

  2. David Wier Guest

    Check out the FindControl method for the FormView


    David Wier
    http://aspnet101.com
    http://iWritePro.com - One click PDF, convert .doc/.rtf/.txt to HTML with no
    bloated markup


    <> wrote in message
    news:...
    >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
     
    David Wier, May 5, 2008
    #2
    1. Advertisements

  3. Stan Guest

    On 5 May, 21:54, wrote:
    > 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
     
    Stan, May 6, 2008
    #3
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Raymond Du

    Computed columns in datagrid

    Raymond Du, Dec 1, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    2,797
    Joe Fallon
    Dec 2, 2004
  2. Paul Aspinall
    Replies:
    1
    Views:
    8,654
    Peter Blum
    Feb 14, 2006
  3. Phillip Vong
    Replies:
    3
    Views:
    643
    Phillip Vong
    Oct 20, 2006
  4. Chris

    Formview within Formview

    Chris, May 19, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    834
    Chris
    May 19, 2007
  5. Gabriel Rossetti
    Replies:
    3
    Views:
    812
    Jerry Hill
    Apr 25, 2008
  6. Sohail Somani
    Replies:
    5
    Views:
    833
    Sohail Somani
    May 7, 2009
  7. David Thielen

    FormView/Repeater/ Eval(FormView data)

    David Thielen, Jun 16, 2006, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    948
    David Thielen
    Jun 16, 2006
  8. James Kuyper

    Computed values don't tie up

    James Kuyper, Apr 3, 2012, in forum: C Programming
    Replies:
    13
    Views:
    699
    Ben Bacarisse
    Apr 4, 2012
Loading...