ASP GridView Color Only Date In Table Cell Text?

WorknHardr
WorknHardr used Ask the Experts™
on
I have a GridView with cells containing both Text and Date.
I would like to color only the Date as blue.
Can this be done?
I'm open to JQuery solution too.

[Cell Data]
   $377.83
 04/01/2013

or

Not Found
04/01/2013
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2013

Commented:
How does your GV markup look like?
You can use Template field and use a Label to display the Date. Set the color for the label accordingly.

Author

Commented:
It's a dynamically created Gridview. I'll get some code posted.
Is the date always in it's own column?
Exploring SQL Server 2016: Fundamentals

Learn the fundamentals of Microsoft SQL Server, a relational database management system that stores and retrieves data when requested by other software applications.

Author

Commented:
I got to work this way since its dynamically rendered. Would be nice to replace the 'For' iteration with a 'Foreach' if possible. It will fail if the columns count changes.

Note: the html color tag is in the database table and could not render properly unless the Gridview uses the HtmlDecode per/row. This is problem when AutoGenerateColumns="true"

 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
 {
     if (e.Row.RowType == DataControlRowType.DataRow)
     {
         for (int i = 7; i < 22; i++)
         {
             e.Row.Cells[i].Text = Server.HtmlDecode(e.Row.Cells[i].Text);
         }
      }
 }

Open in new window

Solution:
   The html color tag is in the database table and could not render properly unless the Gridview uses HtmlDecode per/row. This is problem when AutoGenerateColumns="true"

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
 {
     if (e.Row.RowType == DataControlRowType.DataRow)
     {
           int cols = GridView1.Columns.Count + 1;          

         for (int i = 7; i < cols; i++)
         {
             e.Row.Cells[i].Text = Server.HtmlDecode(e.Row.Cells[i].Text);
         }
      }
 }

Open in new window

Author

Commented:
Discovered my own answer...

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial