Change Forecolor Af a Special Word in Gridview Cell

change forecolor af a special word in gridview cell

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

<style>
.redWord
{
color: Red;
}
.blueWord
{
color: Blue;
}
.yellowWord
{
color: Yellow;
}
</style>

then replace all occurences of Special to <span class='redWord'>Special</span>, Perishable to <span class='blueWord'>Perishable</span>, and Danger to <span class='yellowWord'>Danger</span>:

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", "<span class='redWord'>Special</span>")
.Replace("Perishable", "<span class='blueWord'>Perishable</span>")
.Replace("Danger", "<span class='yellowWord'>Danger</span>");
}
}

Change specific word color in gridview

You need to use the CellPainting event to customize how the cell is drawn. Check this answer, hope it will help you.



Related Topics



Leave a reply



Submit