OnDataItemBound event question

Discussion in 'ASP .Net Datagrid Control' started by djc, Dec 14, 2004.

  1. djc

    djc Guest

    one of the columns in my datagrid shows a date. I want to display dates <
    the current date in red text. I believe I should be using the
    OnDataItemBound event for this. Here is the problem I am having. When using
    e.Item.Cells(4).Text I am getting the actual text displayed in the cell and
    not the value from the database field. For example when this database field
    is null the value of e.Item.Cells(4).Text ends up "&nbsp;". This alone is ok
    because I can count on it and test for it in my code. My issue gets a little
    more sticky because the condition to display the text in red or not is 2
    part. Condition to display text in red in pseudo code: (DateColumn < Today
    AND StatusColumn = "In Progress"). The StatusColumn is a template column and
    so its e.Item.Cells(5).Text winds up with <span> tags and may or may not
    also show an <img> tag. So how do I handle this? I need to use the actual
    database field values for my comparison... how do I get to them?

    any info is greatly appreciated.
     
    djc, Dec 14, 2004
    #1
    1. Advertisements

  2. The easiest solution is to add a hidden column with original database value
    and count on it rather then on it's templated presentation.

    Eliyahu
     
    Eliyahu Goldin, Dec 15, 2004
    #2
    1. Advertisements

  3. djc

    djc Guest

    thanks for the input.

     
    djc, Dec 15, 2004
    #3
  4. djc

    djc Guest

    I think I may have found what I needed... DataItem? e.DataItem("fieldName")?
    I'm actually on my way out and won't be able to work on this today... can
    anyone confirm that that is how I should access the underlying database data
    from the OnDataBound event handler in a datagrid?

    thanks again!
     
    djc, Dec 15, 2004
    #4
  5. djc

    djc Guest

    I think I may have found what I needed... DataItem? e.DataItem("fieldName")?
    I'm actually on my way out and won't be able to work on this today... can
    anyone confirm that that is how I should access the underlying database data
    from the OnDataBound event handler in a datagrid?

    thanks again!
     
    djc, Dec 15, 2004
    #5
  6. For a BoundColumn you can use DataField property which gives you the name of
    the field. You still need to find the record. The way I suggested is much
    simpler. And you don't add anything to the internet traffic since hidden
    columns don't render to client.

    Eliyahu
     
    Eliyahu Goldin, Dec 15, 2004
    #6
  7. djc

    djc Guest

    ok. Thanks again!

     
    djc, Dec 16, 2004
    #7
  8. djc

    Maddy Guest

    DataRowView r = (DataRowView) e.Item.DataItem;

     
    Maddy, Dec 17, 2004
    #8
  9. djc

    djc Guest

    THANK YOU!

     
    djc, Dec 17, 2004
    #9
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.
Similar Threads
There are no similar threads yet.
Loading...