Format A Databound Control In A GridView

This is just a little bit that I keep forgetting for some reason.  Lets say I have a gridview, and in it I want to display the date.  Just the date, but I do not want to use the SQL method to format the date.  You just add the format string to the binding.

Text='<%# Bind("myDate", "{0:MM/dd/yyyy}") %>'

This really would work with any kind of formatting that you needed to do.  I just felt that date would make an easier example.

About SheldonS

Web developer for over 15 years mainly with Microsoft technologies from classic ASP to .NET 4. Husband, father, and aspiring amateur photographer.

Posted on September 1, 2011, in Bits. Bookmark the permalink. Leave a comment.

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: