[此文来源于互联网,牛C网只负责收集整理]

可能之前不少朋友也已经试过,但我是今天才遇到这个问题,翻查资料后才解决。主要是在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>

        

            


作者:gdgzboy@牛C网
地址:http://www.niuc.net/post/3040/
版权所有。转载时必须以链接形式注明作者和原始出处及本声明!



评论(0) | 引用(0) | 阅读(129)
发表评论
昵称 [注册]
密码 游客无需密码
网址
电邮
打开HTML 打开UBB 打开表情 隐藏 记住我