Datagrid ItemDatabound event ??

Discussion in 'ASP .Net' started by =?Utf-8?B?c2VyZ2UgY2FsZGVyYXJh?=, Nov 21, 2005.

  1. Dear all,

    What is the way to check the value of a particular item in a particular cell
    and then set its forground property in red in case of a certain value ??

    I have done the following but do dot work :

    ============================
    Select Case e.Item.ItemType
    Case ListItemType.Item

    If IsNumeric(e.Item.Cells(e.Item.ItemIndex).Text) Then
    If CInt(e.Item.Cells(e.Item.ItemIndex).Text) = 945370550
    Then
    e.Item.BackColor = Color.Red
    e.Item.ForeColor = Color.White

    End If
    End If
    End Select

    what dis I miss ?

    thnaks for your help
    regards
    serge
     
    =?Utf-8?B?c2VyZ2UgY2FsZGVyYXJh?=, Nov 21, 2005
    #1
    1. Advertising

  2. Serge,

    Your first step should be to remove your check for is numeric and that the
    text is equal to 945370550 to see if every cell is then colored. That will
    let you know if the problem is that the cell isn't being colored or if one
    of your checks is not written correctly.

    --
    Sincerely,

    S. Justin Gengo, MCP
    Web Developer / Programmer

    www.aboutfortunate.com

    "Out of chaos comes order."
    Nietzsche
    "serge calderara" <> wrote in
    message news:...
    > Dear all,
    >
    > What is the way to check the value of a particular item in a particular
    > cell
    > and then set its forground property in red in case of a certain value ??
    >
    > I have done the following but do dot work :
    >
    > ============================
    > Select Case e.Item.ItemType
    > Case ListItemType.Item
    >
    > If IsNumeric(e.Item.Cells(e.Item.ItemIndex).Text) Then
    > If CInt(e.Item.Cells(e.Item.ItemIndex).Text) =
    > 945370550
    > Then
    > e.Item.BackColor = Color.Red
    > e.Item.ForeColor = Color.White
    >
    > End If
    > End If
    > End Select
    >
    > what dis I miss ?
    >
    > thnaks for your help
    > regards
    > serge
     
    S. Justin Gengo, Nov 21, 2005
    #2
    1. Advertising

  3. e.Item.ItemIndex is the index of the item in the datagrid's Items
    collection. It has nothing to do with Cells collection. To get to a cell,
    you need to specify it's column number, 0-based. For example,
    e.Item.Cells(3) points to the 4th cell in the row.

    Eliyahu

    "serge calderara" <> wrote in
    message news:...
    > Dear all,
    >
    > What is the way to check the value of a particular item in a particular
    > cell
    > and then set its forground property in red in case of a certain value ??
    >
    > I have done the following but do dot work :
    >
    > ============================
    > Select Case e.Item.ItemType
    > Case ListItemType.Item
    >
    > If IsNumeric(e.Item.Cells(e.Item.ItemIndex).Text) Then
    > If CInt(e.Item.Cells(e.Item.ItemIndex).Text) =
    > 945370550
    > Then
    > e.Item.BackColor = Color.Red
    > e.Item.ForeColor = Color.White
    >
    > End If
    > End If
    > End Select
    >
    > what dis I miss ?
    >
    > thnaks for your help
    > regards
    > serge
     
    Eliyahu Goldin, Nov 21, 2005
    #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. Dave

    ItemDataBound event of DataGrid

    Dave, Oct 7, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    2,952
    Scott Allen
    Oct 7, 2004
  2. MattB
    Replies:
    4
    Views:
    21,305
  3. Replies:
    1
    Views:
    969
    =?Utf-8?B?RWx0b24gVw==?=
    Jan 25, 2006
  4. GaryDean
    Replies:
    1
    Views:
    8,698
    Walter Wang [MSFT]
    Aug 18, 2006
  5. NH
    Replies:
    2
    Views:
    534
    Andrew L. Van Slaars
    Dec 17, 2004
Loading...

Share This Page