Search code examples
c#asp.netgridviewrowdatabound

How to chage the disabled hyperlink color in gridview?


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

Solution

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