Results 1 to 5 of 5

Thread: [RESOLVED]setting gridview cell forecolor to backcolor

  1. #1

    Thread Starter
    Fanatic Member ZeBula8's Avatar
    Join Date
    Oct 2002
    Posts
    548

    Resolved [RESOLVED]setting gridview cell forecolor to backcolor

    I have a gridview in which i would like to 'hide' certain text in the cell.

    Certain rows, I need to have the text hidden and
    To achieve this, I want to set the tablecell's forecolor to the tablecell's backcolor property, thereby making the text invisible and hiding it.



    In the RowDataBound event I have tried using this:

    Code:
            Dim tc As TableCell = e.Row.Cells(4)
            tc.ForeColor = tc.BackColor
            tc = e.Row.Cells(5)
            tc.ForeColor = tc.BackColor
    but when I step through this the BackColor is always rgb(0,0,0,0)

    Does anyone know how I can achieve this ?
    Last edited by ZeBula8; Apr 3rd, 2007 at 10:28 PM. Reason: Resolved

  2. #2
    Frenzied Member StrangerInBeijing's Avatar
    Join Date
    Mar 2005
    Location
    Not in Beijing
    Posts
    1,666

    Re: setting gridview cell forecolor to backcolor

    dude, actually I know nothing about this, so this is probably what I would do if I ran into this problem.

    Make the color's private variables to the page (private string offColor= "#234234";, etc) and then use them where ever you need them?

    Or switch between style classes (you do use style sheets don't you?)
    Install and Configure Eclipse For both Java and PHP development
    Accessible Ajax/jQuery Forms Degrade gracefully with JavaScript Disabled

  3. #3

    Thread Starter
    Fanatic Member ZeBula8's Avatar
    Join Date
    Oct 2002
    Posts
    548

    Re: setting gridview cell forecolor to backcolor

    Actually, the rows are alternating so I won't know what row will have a particular colour at runtime.

  4. #4
    Frenzied Member StrangerInBeijing's Avatar
    Join Date
    Mar 2005
    Location
    Not in Beijing
    Posts
    1,666

    Re: setting gridview cell forecolor to backcolor

    every second row?
    In such case put a counter in your loop (say i++ for each iteration) and then just :
    if (i%2 = 0)
    //use this color;
    else
    //use other color
    Install and Configure Eclipse For both Java and PHP development
    Accessible Ajax/jQuery Forms Degrade gracefully with JavaScript Disabled

  5. #5

    Thread Starter
    Fanatic Member ZeBula8's Avatar
    Join Date
    Oct 2002
    Posts
    548

    Re: setting gridview cell forecolor to backcolor

    After much playing around - I found a couple of nice properties for GridView:

    And then in the RowDataBound event of the GridView:

    Code:
    If e.Row.RowType = DataControlRowType.DataRow Then
            Dim AlternatingRowStyleValue As TableItemStyle
            Dim RowStyleValue As TableItemStyle
    
            AlternatingRowStyleValue = Me.GridView1.AlternatingRowStyle
            RowStyleValue = Me.GridView1.RowStyle
    
            If e.Row.RowIndex Mod 2 Then
              e.Row.Cells(4).ForeColor = AlternatingRowStyleValue.BackColor
              e.Row.Cells(5).ForeColor = AlternatingRowStyleValue.BackColor
            Else
              e.Row.Cells(4).ForeColor = RowStyleValue.BackColor
              e.Row.Cells(5).ForeColor = RowStyleValue.BackColor
            End If
    End If
    This effectively renders my selected text invisible....

    Thanks, Stranger, for the Mod idea...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width