Hi EmadKhan,
Refer the below code.
HTML
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" AllowPaging="true"
Caption="ORIGINAL STATE">
<Columns>
<asp:BoundField DataField="Text1" HeaderText="Text1" />
<asp:BoundField DataField="Text2" HeaderText="Text2" />
<asp:BoundField DataField="Text3" HeaderText="Text3" />
<asp:BoundField DataField="Text4" HeaderText="Text4" />
<asp:BoundField DataField="Text5" HeaderText="Text5" />
</Columns>
</asp:GridView>
<br />
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="false" AllowPaging="true"
OnRowDataBound="OnRowDataBound" Caption="WANTED STATE">
<Columns>
<asp:BoundField DataField="Text1" HeaderText="Text1" />
<asp:BoundField DataField="Text2" HeaderText="Text2" />
<asp:BoundField DataField="Text3" HeaderText="Text3" />
<asp:BoundField DataField="Text4" HeaderText="Text4" />
<asp:BoundField DataField="Text5" HeaderText="Text5" />
</Columns>
</asp:GridView>
</div>
Code
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[5] { new DataColumn("Text1"), new DataColumn("Text2"), new DataColumn("Text3"), new DataColumn("Text4"), new DataColumn("Text5") });
dt.Rows.Add("1", "Builder", "1234", "something,good", "Invalid");
dt.Rows.Add("2", "!)@(#*", "good", "good", "good");
dt.Rows.Add("3", "&-,.", "perfect", "`~!@#$%^*()_+={[}];:'\",<>/?\\|", "perfect,poor");
GridView1.DataSource = dt;
GridView1.DataBind();
GridView2.DataSource = dt;
GridView2.DataBind();
}
}
protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
var searches = new[] { "]", "`", "~", "!", "@", "#", "$,", "%", "^", "*", "(", ")", "_", "+", "=", "{", "}", ";", ":", "'", "\"", ",", "<", ">", "/", "?", @"\\", "|", "[" };
var regex = "[" + String.Join("", searches) + "]";
for (int i = 0; i < e.Row.Cells.Count; i++)
{
e.Row.Cells[i].Text = Regex.Replace(System.Net.WebUtility.HtmlDecode(e.Row.Cells[i].Text), regex, delegate(Match match)
{
return string.Format("<span style = 'color:Red'>{0}</span>", match.Value);
}, RegexOptions.IgnoreCase);
}
}
}
Output
ORIGINAL STATE
Text1 | Text2 | Text3 | Text4 | Text5 |
1 |
Builder |
1234 |
something,good |
Invalid |
2 |
!)@(#* |
good |
good |
good |
3 |
&-,. |
perfect |
`~!@#$%^*()_+={[}];:'",<>/?\| |
perfect,poor |
WANTED STATE
Text1 | Text2 | Text3 | Text4 | Text5 |
1 |
Builder |
1234 |
something,good |
Invalid |
2 |
!)@(#* |
good |
good |
good |
3 |
&-,. |
perfect |
`~!@#$%^*()_+={[}];:'",<>/?\| |
perfect,poor |