"dch3" <dc**@discussions.microsoft.comwrote in message
news:49**********************************@microsof t.com...
>>Is there a way to conditionally format a dateTime field
A dateTime field...?
A field from a database displayed in a GridView.
Ah...
My experience is with Classic ASP.
The best advice I can give you is to forget everything you ever knew about
ASP Classic and learn ASP.NET properly from the ground up. The biggest
mistake people make when coming from ASP Classic to ASP.NET is to assume
that ASP.NET is somehow the "next version" of ASP Classic. It isn't - not
even close. ASP.NET is different from ASP Classic in almost every way,
mainly due to the .NET Framework.
It's a steep learning curve. I'd suggest you get a copy of these:
http://www.amazon.com/Beginning-ASP-...6236712&sr=8-2 http://www.amazon.com/Pro-ASP-NET-20...6236712&sr=8-1
and work your way through them.
Anyway, to answer your question, you'll need to wire up the GridView's
OnRowDataBound event:
http://www.google.co.uk/search?sourc...OnRowDataBound
This will allow you to modify the values of a row's cells as they are being
bound to the GridView. E.g. if the date value was contained in the third
column of the GridView, you might do something like this:
<asp:GridView ID="gvResults" runat="server"
OnRowDataBound="gvResults_RowDataBound">
protected void gvResults_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DateTime dtmCell = DateTime.Parse(e.Row.Cells[2].Text);
e,Row.Cells[2].Text = dtmCell.ToString("ddd MM/dd/yy").ToUpper();
if (dtmCell.Hour + dtmCell.Minute + & dtmCell.Second 0)
{
e.Row.Cells[2].Text += "<br />" + dtm.Cell.ToString("hh:mm tt");
}
}
}
Also, be aware that the date format FRI 10/31/08 is not Y2K-compliant
because it doesn't display a 4-digit year, and is also internationally
ambiguous. E.g. in that format, today's date would be
"SUN 11/09/08"
In the vast majority of the world, that would be interpreted as 11th
September 2008, not 9th November 2008 and, depending on what it was used
for, would fail validation because 11th September 2008 was a Tuesday, not a
Sunday. In some parts of the world, that would be interpreted as 8th
September 2011.
If your web app is intended to be used by anyone outside the US and some
parts of Canada, Kenya and the Philippines, you should not use this date
format:
http://en.wikipedia.org/wiki/Image:Date.png
--
Mark Rae
ASP.NET MVP
http://www.markrae.net