|
-
Apr 3rd, 2007, 07:00 PM
#1
Thread Starter
Fanatic Member
[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
-
Apr 3rd, 2007, 07:38 PM
#2
Frenzied Member
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?)
-
Apr 3rd, 2007, 08:09 PM
#3
Thread Starter
Fanatic Member
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.
-
Apr 3rd, 2007, 08:37 PM
#4
Frenzied Member
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
-
Apr 3rd, 2007, 10:28 PM
#5
Thread Starter
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|