Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Format Date in Bind Statement inside a ListView

is there a way that I can format a Date binded in a ListView?

I have this snippet of ListView

<ListView ID="lvView" runat="server">
    <ItemTemplate>
        //... some bounded data
        <asp:Label ID="lblDate" runat="server" Text='<%# Bind("RequiredDate") %>' />
        //... another bounded data
    </ItemTemplate>
</ListView>

Since RequiredDate is a DateTime it will display somethine like this 10/20/2010 11:08:55 AM

What I want is to Format that date to output something like this Oct. 20, 2010. Normally if it is a DateTime I can write something like this requiredDate.ToString("MMMM dd, yyyy") but inside the ListView binded data I cannot do that.

I don't want to use OnItemDatabound. I just want it to be formatted inline. Is this possible?

like image 723
rob waminal Avatar asked Oct 20 '10 03:10

rob waminal


2 Answers

Should be like...

Text='<%# Bind("RequiredDate", "{0:MMM dd, yyyy}") %>'
like image 81
Muhammad Akhtar Avatar answered Sep 21 '22 00:09

Muhammad Akhtar


This should work

Text='<%# Bind("DateOfBirth", "{0:MMM dd, yyyy}") %>'
like image 24
Ashaar Avatar answered Sep 17 '22 00:09

Ashaar