Solved

ASP GridView Color Only Date In Table Cell Text?

Posted on 2014-02-26
6
297 Views
Last Modified: 2014-03-08
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
0
Comment
Question by:WorknHardr
  • 4
6 Comments
 
LVL 41

Expert Comment

by:guru_sami
Comment Utility
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.
0
 

Author Comment

by:WorknHardr
Comment Utility
It's a dynamically created Gridview. I'll get some code posted.
0
 
LVL 14

Expert Comment

by:CtrlAltDl
Comment Utility
Is the date always in it's own column?
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:WorknHardr
Comment Utility
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

0
 

Accepted Solution

by:
WorknHardr earned 0 total points
Comment Utility
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

0
 

Author Closing Comment

by:WorknHardr
Comment Utility
Discovered my own answer...
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now