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
Getting Selected Value of a Combobox
Spawn a New Thread to Open a New Window and Close It from a Different Thread
Using a Wwwroot Folder (ASP.NET Core Style) in ASP.NET 4.5 Project
How to Lock/Unlock a File Across Process
SQL Connection String for Microsoft Access 2010 .Accdb
How Could the New Async Feature in C# 5.0 Be Implemented with Call/Cc
Onchange Event for HTML.Dropdownlist
How to Remove Specific Style Tag in HTML Using C#
Execute SQL Script on SQL Server Using C#
Creating Safe SQL Statements as Strings
C# - How to Prevent Mousewheel-Scrolling in My Combobox
Multiple SQL Statements in One Roundtrip Using Dapper.Net
Deploying ASP.NET Web Forms Project to Fedora 24
How to Get Data by SQLdatareader.Getvalue by Column Name
Are P/Invoke [In, Out] Attributes Optional for Marshaling Arrays
How to Get The Checkboxlist Selected Values, What I Have Doesn't Seem to Work C#.Net/Visualwebpart
How to Convert Style Text to C# Object Such as Class/Hashtable/Collection