0

In Gridview RowDataBound I am disabling hyperlink based on its value. But hyperlink text is grayed out.
I want to change the fore color of the disabled hyperlink, so that I can read text easily.

I tried as mentioned below.

protected void gridResult_RowDataBound(object sender, GridViewRowEventArgs e) 
{       
    var hyperlink = e.Row.FindControl( "hlink" ) as HyperLink;
    if( hyperlink!= null && hyperlink.Text =="ABC" )
    {
        hyperlink.ForeColor = Color.Black;
        hyperlink.Enabled = false;
    }
}
Vishal Suthar
  • 17,013
  • 3
  • 59
  • 105
Ranjith
  • 549
  • 4
  • 10
  • 20
  • Might be the duplicate of [Change cell color on different values - Gridview][1] [1]: http://stackoverflow.com/questions/4427848/change-cell-color-on-different-values-gridview – Ram Jul 12 '12 at 13:54

3 Answers3

0

I think what you really want to do is enable the TextBox and set the ReadOnly property to true.

It's a bit tricky to change the color of the text in a disabled TextBox. I think you'd probably have to subclass and override the OnPaint event.

Vishal Suthar
  • 17,013
  • 3
  • 59
  • 105
0

You can set the ForeColor by the CssClass property of HyperLink

HatSoft
  • 11,077
  • 3
  • 28
  • 43
0

I'd say add a class to the link instead of setting ForeColor and use CSS to style the disabled link.

hyperlink.CssClass = "disabledLink";

then in CSS:

.disabledLink {
  color: #000 !important;
}
Candide
  • 30,469
  • 8
  • 53
  • 60
  • I tried as you said, But it didn't solve my problem. It is still grayed out. I think we can't add css class to disabled hyperlinks. – Ranjith Jul 12 '12 at 14:12
  • Yes you can add a css class to a disabled `HyperLink`. It may be grayed out because .net places a css class `aspNetDisabled`, which your styles may be customizing. I added `!important` to the css so it overrides the current styles. – Candide Jul 12 '12 at 14:35