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. Advertising

  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. Advertising

  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. Advertising

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,562
    Joe Fallon
    Dec 2, 2004
  2. John Dalberg
    Replies:
    1
    Views:
    420
    Bruce Barker
    Feb 3, 2006
  3. Replies:
    2
    Views:
    851
    Adam Maass
    May 24, 2005
  4. Sohail Somani
    Replies:
    5
    Views:
    626
    Sohail Somani
    May 7, 2009
  5. James Kuyper

    Computed values don't tie up

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

Share This Page