Gridview Date Format Problem

J

Jules Wensley

Hi

I have a Gridview in ASP.Net 2.0. I'm populating it with data from a SQL
2005 database (but with legacy design).
In the DB, the dates are stored as DateTime - DD/MM/YY HH:MM:SS.

In the bound Gridview, I'm applying the {0:d} format (to show just the short
date).

The date is still displayed in the same format as the DB.

Anybody know of a solution to this, or am I going to populate the Gridview
manually, applying formatting then.

Thanks in advance for your assistance.

Jules
 
E

Eliyahu Goldin

Jules,

My information is based on 1.1 but it's likely still valid for 2.0.

0:d is for numbers. You can't format date in such a way. You should catch
ItemDataBound or PreRender event, get the string content of the cell,
convert it to DateTime and than back to string with a valid date format
expression.

Eliyahu
 
J

Jose A. Fernandez

I have idem problem.
But my quikly solution is

Into event:
gvFacturas_RowDataBound....
{...actions....}
Select Case e.Row.RowType
{...actions....}
Case DataControlRowType.DataRow
{...actions....}
Dim Fecha As Date =
CType(DataBinder.Eval(e.Row.DataItem, "FacturaFecha"), Date)
e.Row.Cells(2).Text =
Fecha.ToShortDateString

I hope it works..!
 
J

Jules Wensley

Thanks very much, all. In the end, I just amended the SQL string. We're going
to SQL Server 2005 next week, so we'll be able to do it properly!

Jules
Hi,
 
C

ctrlaltdl

Follow Teemu's advice then your formatting will work!

This seems to be a bug to me, because everyone asks this question why
the formatting isn't working.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top