Вопрос

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;
    }
}
Это было полезно?

Решение

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;
}

Другие советы

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.

You can set the ForeColor by the CssClass property of HyperLink

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top