I have a simple XML doc with an XSD. It has a single root node, with several child nodes all with attributes of 'Name' (String), 'Text' (String) and Date (DateTime).
I'm using an XmlDataProvider which references my XML file. The XmlDataProvider is then bound to a DataList. The bind works, and I can see my data presented as desired in the DataList at runtime. My problem is that I wish to format the Date so that it is
displayed yyyy-mm-dd. I have specifying the DataFormatString for the 'date' boundcolumn, but have had no luck in getting this to work. What is the easiest way to do this? My dates are properly encoded in the xml file in ISO standard yyyy-mm-ddThh:mm:ss.mmm
etc.
geedubb
Member
202 Points
44 Posts
Format date from XML using DataFormatString??
Sep 14, 2006 01:24 PM|LINK
Hi
I have a simple XML doc with an XSD. It has a single root node, with several child nodes all with attributes of 'Name' (String), 'Text' (String) and Date (DateTime).
I'm using an XmlDataProvider which references my XML file. The XmlDataProvider is then bound to a DataList. The bind works, and I can see my data presented as desired in the DataList at runtime. My problem is that I wish to format the Date so that it is displayed yyyy-mm-dd. I have specifying the DataFormatString for the 'date' boundcolumn, but have had no luck in getting this to work. What is the easiest way to do this? My dates are properly encoded in the xml file in ISO standard yyyy-mm-ddThh:mm:ss.mmm etc.
Any help greatly appreciated.
Cheers
jcw14
Contributor
2919 Points
577 Posts
Re: Format date from XML using DataFormatString??
Sep 14, 2006 10:05 PM|LINK
You could use XmlConvert to convert to a DateTime, something like this
<ItemTemplate>
date:
<asp:LabelID="dateLabel" runat="server" Text='<%# System.Xml.XmlConvert.ToDateTime(XPath("@date").ToString()).ToShortDateString() %>'></asp:Label>
</ItemTemplate>
My Blog: http://www.wintersfamily.plus.com/blogs/JamesWinters
geedubb
Member
202 Points
44 Posts
Re: Format date from XML using DataFormatString??
Sep 16, 2006 10:59 AM|LINK