Solved

ASP GridView Color Only Date In Table Cell Text?

Posted on 2014-02-26
6
304 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
Technology Partners: 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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Suggested Courses

734 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