change forecolor af a special word in gridview cell

前端 未结 2 1799
有刺的猬
有刺的猬 2021-01-22 23:21

I want to change the color of some special words NOT all words in a gridview cell. Here is the code:

protected void gvContents_RowDataBound(obj         


        
2条回答
  •  既然无缘
    2021-01-22 23:43

    Use a combination of span tags and CSS classes. First create the CSS classes in your aspx code:

    
    

    then replace all occurences of Special to Special, Perishable to Perishable, and Danger to Danger:

    protected void gvContents_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Cells[3].Text = e.Row.Cells[3].Text.Replace("Special", "Special")
                                  .Replace("Perishable", "Perishable")
                                  .Replace("Danger", "Danger");
        }
    }
    

提交回复
热议问题