zoukankan      html  css  js  c++  java
  • GridView日期格式模版列使用方法 (转)

    在asp.net 2.0中,如果要在绑定列中显示比如日期格式等,如果用下面的方法是显示不了的
     
    <asp :BoundField DataField=“CreationDate” 
         DataFormatString=“{0:M-dd-yyyy}” 
         HeaderText=“CreationDate”   />

    主要是由于htmlencode属性默认设置为true,已防止XSS攻击,安全起见而用的,所以,可以有以下两种方法解决
    1、
    <asp :GridView ID=“GridView1″ runat=“server”>
    <columns>
      <asp :BoundField DataField=“CreationDate” 
         DataFormatString=“{0:M-dd-yyyy}” 
         HtmlEncode=“false”
         HeaderText=“CreationDate”    />
    </columns>
    </asp>
    将htmlencode设置为false即可

    另外的解决方法为,使用模版列
    <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>
  • 相关阅读:
    HTTP协议
    HTTP请求
    scoket
    Git的简绍
    SpringBoot添加“热部署”
    SpringBoot入门(简绍和案例)
    JVisual VM工具使用以及垃圾回收机制
    jstack应用
    Jvm优化(1)
    Spring Data ElasticSearch的使用十个小案例
  • 原文地址:https://www.cnblogs.com/kingboy/p/1033401.html
Copyright © 2011-2022 走看看