Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > dataformatstring template column why is getting a short date so ha

Reply
Thread Tools

dataformatstring template column why is getting a short date so ha

 
 
cindy
Guest
Posts: n/a
 
      04-19-2006
I have datagrid, datasource datafield is datetime so its
ugly date time etc ugly I want short date
in datagrid column is datetime datatype so it sorts right
not like text so thats good but its ugly

have tried this but the error is invalid cast
<asp:TemplateColumn SortExpression="reviseddate" HeaderText="Revised Date">
<ItemTemplate><asp:Label runat="server" Text='<%#
((DateTime)DataBinder.Eval(Container.DataItem,
"reviseddate")).ToShortDateString() %>' ID="Label2"></asp:Label>
</ItemTemplate>

have tried this but then the grid just does not display it binds and then
cannot display

the code below was auto created, as a bound column the use of
dataformatstring
works great then using property builder in design mode and convert to
template
column you get code below but then run and no grid display

<ItemTemplate><asp:Label runat="server" Text='<%# DataBinder.Eval(Container,
"DataItem.reviseddate", "{0:d}") %>'></asp:Label></ItemTemplate>


--
cindy
 
Reply With Quote
 
 
 
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      04-20-2006
Hi cindy,

Thank you for posting.

Regarding the data formatting in DataGrid column for DateTime data field, I
think it is likely the data binding expression in the first code snippet
you pasted hasn't been evaluated correctly by the runtime. I think you can
try call the GetType method on the returned object and print it out to see
whether it is of the correct type like DataBinder.Eval(Container.DataItem,
"reviseddate").GetType().ToString(). Also, the casting error may also
occur on other step in the databinding. You can define a helper function in
the page's codebehind class to do the formatting. e.g:

<%# MyConvertFunc( DataBinder.Eval(......)) %>

in code behind, define:

protected string MyConvertFunc(object obj)
{
.................
}

Please feel free to let me know if there is anything else I missed.

Hope this helps.

Regards,

Steven Cheng
Microsoft Online Community Support


==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================


This posting is provided "AS IS" with no warranties, and confers no rights.



Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

 
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
Adding a column to a GridView at Runtime and DataFormatString Eamonn ASP .Net 5 11-18-2008 04:51 AM
DataFormatString not working on a GridView DateTime column Rob Roberts ASP .Net 3 04-13-2007 07:33 PM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
Short date format in template column? clucherini@gmail.com ASP .Net Datagrid Control 1 05-19-2006 07:24 AM
Date, date date date.... Peter Grison Java 10 05-30-2004 01:20 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57