Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
346 views
Welcome To Ask or Share your Answers For Others

1 Answer

Should be like...

Text='<%# Bind("RequiredDate", "{0:MMM dd, yyyy}") %>'

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...