The easiest way to format a SharePoint FieldValue

    The FieldValue control in the SharePoint.WebControls namespace is nice to use for displaying values from a SPListItem without adding a lot of “unnecessary” code.
    For example, this will get you a display of the created date of an item:

    <msw:FieldValue runat=”server”FieldName=”Created” />With the following look:


    What if you now want to format the date, how do you do that?
    No rocket science , but you can (either in your page or perhaps usercontrol) add some declarative code to format that date according to the following pattern:


    <%= DateTime.Parse(Microsoft.SharePoint.SPContext.Current.Item&#91;"Created"&#93;.ToString()).ToString("d MMM yyyy") %>

     And the look is now as follows: 



  1. #1 by Thomas Goddard on April 22, 2010 - 08:03

    This post was most helpful. Thank you for sharing!

    • #2 by Johan Leino on April 22, 2010 - 19:02

      You are welcome. Glad I could be of assistance.

  2. #3 by Alla on February 17, 2011 - 22:11

    This is very useful. Thanks for this post.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: