NeGueSa
asked on
Put a Gridview row in a specific color.
I'm using Visual Studio 2005, but programing in Visual Basic I want to know what code implement in RowDataBound Procedure to put an specific row in a different color when a cell in that row has an specific value.
Let say that my grid has the name of "GrdBrokers" and I want to put the entire row in red color when the cell # 5 has the value of "DELETED"
Let say that my grid has the name of "GrdBrokers" and I want to put the entire row in red color when the cell # 5 has the value of "DELETED"
ASKER
That's work with backcolor, but what about forecolor, it doen't work for forecolor
Protected Sub GridView1_RowDataBound(ByV al sender As Object, ByVal e As System.Web.UI.WebControls. GridViewRo wEventArgs ) Handles GridView1.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
If e.Row.Cells(5).Text = "DELETED" then
e.Row.ForeColor = Drawing.Color.LightGreen
End if
End If
End Sub
If e.Row.RowType = DataControlRowType.DataRow
If e.Row.Cells(5).Text = "DELETED" then
e.Row.ForeColor = Drawing.Color.LightGreen
End if
End If
End Sub
ASKER
I already test this string and is strange for Font Bold works, but for Forecolor NOT
If e.Row.Cells(7).Text = "DELETED" Then
e.Row.Font.Bold = True
e.Row.ForeColor = Drawing.Color.Red
End If
If e.Row.Cells(7).Text = "DELETED" Then
e.Row.Font.Bold = True
e.Row.ForeColor = Drawing.Color.Red
End If
try e.row.color
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
e.row.color doesn't exist as option, by other hand, iboutchkine good point, no I don't have any CSS attached, but what I have is this which probably doesn't allow me to change the forecolor, bt I can't get rid of this:
function hight_temp(vl,vlw){
if(xState){
if( xState.parentElement.paren tElement != vl) {
if ( vlw == 1 ){
fmr_cl = vl.style.backgroundColor
vl.style.backgroundColor=' #639ABC';
vl.style.color='white';
}
else{
vl.style.backgroundColor= fmr_cl ;
vl.style.color='black';
}
}
}else{
if ( vlw == 1 ){
fmr_cl = vl.style.backgroundColor
vl.style.backgroundColor=' #639ABC';
vl.style.color='white';
}
else{
vl.style.backgroundColor= fmr_cl;
vl.style.color='black';
}
}
}
// -->
This function highlight the grid when you point it
function hight_temp(vl,vlw){
if(xState){
if( xState.parentElement.paren
if ( vlw == 1 ){
fmr_cl = vl.style.backgroundColor
vl.style.backgroundColor='
vl.style.color='white';
}
else{
vl.style.backgroundColor= fmr_cl ;
vl.style.color='black';
}
}
}else{
if ( vlw == 1 ){
fmr_cl = vl.style.backgroundColor
vl.style.backgroundColor='
vl.style.color='white';
}
else{
vl.style.backgroundColor= fmr_cl;
vl.style.color='black';
}
}
}
// -->
This function highlight the grid when you point it
Try to get rid of CSS and then try ForeColor. It must work. It works in my case
ASKER
As I told you iboutchkine is not a CSS is a java function which allow me to highlight each grid row when I point them, and I can not get rid of it, anyway you were the guy who was closer to the "solution" I will give the points.
For each row as GridViewRow in GridView1.Rows
If row.Cells(the cell number of that column).Text = "DELETED" Then
row.BackColor = Drawing.Color.Red
End If
Next