Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > Gridview Date Format Problem

Reply
Thread Tools

Gridview Date Format Problem

 
 
Jules Wensley
Guest
Posts: n/a
 
      12-17-2005

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


 
Reply With Quote
 
 
 
 
Eliyahu Goldin
Guest
Posts: n/a
 
      12-18-2005
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

"Jules Wensley" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) m...
>
> 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
>
>



 
Reply With Quote
 
 
 
 
ctrlaltdl@gmail.com
Guest
Posts: n/a
 
      12-19-2005
I'm not sure I understand your question, but I think what you need is:
{0:MM/dd}

Here are list of the different formats:
http://msdn.microsoft.com/library/de...matstrings.asp

 
Reply With Quote
 
Jose A. Fernandez
Guest
Posts: n/a
 
      12-19-2005
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..!

 
Reply With Quote
 
Teemu Keiski
Guest
Posts: n/a
 
      12-20-2005
Hi,

you mean string formatting doesn't seem to apply when using BoundField?

Set HtmlEncode="false" for the BoundField. That should do it.

For an explanation please see:
http://aspadvice.com/blogs/joteke/ar.../25/12871.aspx

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke



"Jules Wensley" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) m...
>
> 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
>
>



 
Reply With Quote
 
Jules Wensley
Guest
Posts: n/a
 
      12-20-2005
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,
>
> you mean string formatting doesn't seem to apply when using
> BoundField?
>
> Set HtmlEncode="false" for the BoundField. That should do it.
>
> For an explanation please see:
> http://aspadvice.com/blogs/joteke/ar.../25/12871.aspx
> "Jules Wensley" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) m...
>
>> 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
>>



 
Reply With Quote
 
ctrlaltdl@gmail.com
Guest
Posts: n/a
 
      12-20-2005
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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
GridView date format problem Bob Phillips ASP .Net Datagrid Control 2 08-01-2006 06:18 PM
problem with date and date/format Une bévue Ruby 3 03-12-2006 06:00 AM
[Newbie UK Date problem] Ways atround this UK date format localisation/SQLselection issue? DC ASP .Net 5 07-01-2005 09:35 PM
Date, date date date.... Peter Grison Java 10 05-30-2004 01:20 PM
Date Format - best way of converting a string into a date format Brian Candy ASP .Net 2 02-18-2004 02:13 PM



Advertisments