Solved

ASP GridView Color Only Date In Table Cell Text?

Posted on 2014-02-26
6
305 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
6 Comments
 
LVL 41

Expert Comment

by:guru_sami
ID: 39889679
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
ID: 39889894
It's a dynamically created Gridview. I'll get some code posted.
0
 
LVL 14

Expert Comment

by:CtrlAltDl
ID: 39890649
Is the date always in it's own column?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:WorknHardr
ID: 39890777
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
ID: 39900286
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
ID: 39914437
Discovered my own answer...
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

688 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