In Asp.net 2.0, if you want to display data in the binding column, such as the date format, the following method cannot be used. <Asp: boundfield datafield = "creationdate" Dataformatstring = "{0: M-dd-yyyy }" Headertext = "creationdate"/> The main reason is that the htmlencode attribute is set to true by default, which has prevented XSS attacks and is used for security reasons. Therefore, there are two solutions: 1, <Asp: gridview id = "gridview1" runat = "server"> <Columns> <Asp: boundfield datafield = "creationdate" Dataformatstring = "{0: M-dd-yyyy }" Htmlencode = "false" Headertext = "creationdate"/> </Columns> </Asp> Set htmlencode to false. Another solution 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> |