Note: HTMLEncode=True helps prevent cross-site scripting attacks.
In order to display the date in a user friendly date format, use the following method to turn off the HTMLEncode and use :
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataKeyNames="CustomerID"
DataSourceID="SqlDataSource1" AllowPaging="True" AllowSorting="True">
<Columns>
<asp:BoundField DataField="SomeDate" DataFormatString="{0:MM-dd-yyyy}"
HtmlEncode="false" HeaderText="SomeDate" />
...
</Columns>
</asp:GridView>
If you do not want to do it this way, the other way is to use a Template Field as shown below
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataKeyNames="CustomerID"
DataSourceID="SqlDataSource1" AllowPaging="True" AllowSorting="True">
<Columns>
<asp:TemplateField HeaderText="SomeDate" >
<EditItemTemplate>
<asp:Label ID="lblDate" runat="server" Text='<%# Eval("SomeDate", "{0:MM-dd-yyyy}") %>'
</asp:Label>
</EditItemTemplate>
...
</Columns>
</asp:GridView>
Tweet
No comments:
Post a Comment