Asp.net| Tips
Perhaps many friends have tried before, but I only met this problem today, after searching for information to solve. Mainly in ASP.net 2.0, if you want to display the date format in the bound column, and so on, if the following method is not displayed
<asp:boundfield datafield= "CreationDate"
Dataformatstring= "{0:m-dd-yyyy}"
headertext= "CreationDate"/>
This is mainly because the HTMLEncode property is set to True by default and has been prevented from XSS attacks for security reasons, so there are two ways to resolve
1,
<asp:gridview id= "gridview1″runat=" Server >
<columns>
<asp:boundfield datafield= "CreationDate"
Dataformatstring= "{0:m-dd-yyyy}"
Htmlencode= "false"
headertext= "CreationDate"/>
</columns>
</asp>
Set the HTMLEncode to False
Another workaround is to use the template column
<asp:gridview id= "gridview3″runat=" Server >
<columns>
<asp:templatefield headertext= "CreationDate" >
<edititemtemplate>
<asp:label id= "label1″runat=" Server "
Text= ' <%# Eval ("CreationDate", "{0:m-dd-yyyy}")%> ' >
</asp>
</edititemtemplate>
<itemtemplate>
<asp:label id= "Label1" runat= "Server"
Text= ' <%# Bind ("CreationDate", "{0:m-dd-yyyy}")%> ' >
</asp>
</itemtemplate>
</asp>
</columns>
</asp>