Computed columns in datagrid

Discussion in 'ASP .Net' started by Raymond Du, Dec 1, 2004.

  1. Raymond Du

    Raymond Du Guest

    Hi,

    Can I have computed columns in a datagrid? If yes, how?

    TIA
    Raymond Du, Dec 1, 2004
    #1
    1. Advertising

  2. Raymond Du

    mortb Guest

    one way:

    add a column
    insert values in it in the event ItemDatabound

    example column three is your computed value column:

    private void _Grid_ItemDataBound(object sender,
    System.Web.UI.WebControls.DataGridItemEventArgs e)

    {

    if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
    ListItemType.AlternatingItem)

    {

    e.Item.Cells[3].Text = "your computed value";

    }

    }

    cheers,
    mortb

    "Raymond Du" <> wrote in message
    news:uL$...
    > Hi,
    >
    > Can I have computed columns in a datagrid? If yes, how?
    >
    > TIA
    >
    >
    mortb, Dec 1, 2004
    #2
    1. Advertising

  3. =?Utf-8?B?VGFtcGEgLk5FVCBLb2Rlcg==?=, Dec 1, 2004
    #3
  4. Raymond Du

    Joe Fallon Guest

    A 3rd idea would be to do the computation in your data source.
    e.g if it is a custom collection then add a readonly property to the
    contained child class and have it return the computation. Then you can treat
    it as a bound column in the grid.
    --
    Joe Fallon


    "Raymond Du" <> wrote in message
    news:uL$...
    > Hi,
    >
    > Can I have computed columns in a datagrid? If yes, how?
    >
    > TIA
    >
    >
    Joe Fallon, Dec 2, 2004
    #4
    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. John Dalberg
    Replies:
    1
    Views:
    425
    Bruce Barker
    Feb 3, 2006
  2. Replies:
    2
    Views:
    863
    Adam Maass
    May 24, 2005
  3. Pascal Steiss
    Replies:
    1
    Views:
    3,394
    Toby Inkster
    Mar 19, 2005
  4. rob thomson
    Replies:
    0
    Views:
    260
    rob thomson
    Sep 4, 2003
  5. ton
    Replies:
    2
    Views:
    205
    Alvin Bruney [MVP]
    Feb 11, 2004
Loading...

Share This Page