change forecolor af a special word in gridview cell

前端 未结 2 1817
有刺的猬
有刺的猬 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:38

    In the CellFormatting event handler, add the below code

    void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
        {
            if (e.Value != null && e.Value.ToString() == "Special")
            {
                e.CellStyle.ForeColor = Color.Red;
            }
        }
    

提交回复
热议问题