2

Just looking for some strategies to modify the typical

mm/dd/yy 00:00:00 to simply
mm/dd/yy of a datetime item being returned in a dataset that is bound to the gridview

thanks

the item is within a dataset and I am simply doing the following

gridview.DataSource = GetDataSet();
gridview.DataBind();

So I don't have a ton of interaction with the dataset at the moment. I could brute force iterate through it and do something like

foreach(Table)
   foreach(Row)
      grab date Col, format and concat to look as desired

but this is very messy and was wondering if there is a more elegant solution.

Matthew Cox
  • 13,566
  • 9
  • 54
  • 72

1 Answers1

7

Just specify the DataFormatString in the GridView

<asp:BoundField HeaderText="Date" DataField="MyDate" 
     DataFormatString="{0:MM/dd/yy}">
Binoj Antony
  • 15,886
  • 25
  • 88
  • 96
  • I knew there had to be something sexy like this. TY sir – Matthew Cox Dec 03 '10 at 05:27
  • to clarify, I looked up the property and you could just do the following: DataFormatString="{0:d}" but thank you again sir! – Matthew Cox Dec 03 '10 at 05:31
  • 1
    Its matter of preference, I prefer to make it explicit, so that the next programmer who looks at this code for maintenenace need not do the `look up`! – Binoj Antony Dec 03 '10 at 07:42
  • You have a valid point ;) 1 vote for that. I have a co-worker who makes a habit of creating hardly maintainable code so I am all for that. – Matthew Cox Dec 03 '10 at 08:51