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
Solved

ASP GridView Color Only Date In Table Cell Text?

Posted on 2014-02-26
6
302 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
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
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

828 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