Console.WriteLine("Woop!");I have recently been dealing with GridViews quite a bit, and one of the things that annoyed me was the way you had to format a date.
You are normally forced to create a function in your code-behind page, and pass the date to it - Which is annoying if you only ever need to format a single date on the page. Something like the following:
Page.aspx
Page.aspx.cs<asp:TemplateField HeaderText="Date Header Here"><ItemTemplate> <%#FormatDate(Eval("SQLDateValue"))%></ItemTemplate></asp:TemplateField>
public object FormatDate(object input)This was rather annoying, as it seemed like a very roundabout way to do something seemingly small. After messing around a bit, I found a nice compact way to do it in the GridView itself!{
string stringObject = input.ToString();
DateTime dttm = DateTime.Parse(stringObject);
return dttm.ToString("dd-MMM-yyyy");
}
<asp:TemplateField HeaderText="Date Header Here">
<I temTemplate>
<%#DateTime.Parse(Eval(" DateReceived").ToString()). ToString("dd-MMM-yyyy")%>
</ItemTemplate>
</asp:TemplateField>
Win! \o/
On an unrelated note, getting decently formatted ASP.NET / C# code in blogspot is a nightmare >_>
No comments :
Post a Comment