注册 | 登录 | 设为首页 | 加入收藏
您当前的位置:飞翔学院-IT中国 → IT资讯互联网 → 文章内容

在gridview中使用DataFromatString

作者:佚名 来源:不详 发布时间:2007-10-13 14:41:58

    可能之前不少朋友也已经试过,但我是今天才遇到这个问题,翻查资料后才解决。主要是
在asp.net2.0中,如果要在绑定列中显示比如日期格式等,如果用下面的方法是显示不了的
 
<asp:BoundFieldDataField=“CreationDate” 
    DataFormatString=“” 
    HeaderText=“CreationDate”  />

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

另外的解决方法为,使用模版列
<asp:GridViewID=“GridView3″runat=“server” >
 <columns>
 <asp:TemplateFieldHeaderText=“CreationDate”>
  <edititemtemplate>
   <asp:LabelID=“Label1″runat=“server”
     Text=‘<%#Eval("CreationDate","")%>‘>
   </asp>
  </edititemtemplate>
  <itemtemplate>
   <asp:LabelID="Label1"runat="server"
     Text=’<%#Bind(“CreationDate”,“”)%>‘>
   </asp>
  </itemtemplate>
 </asp>
 </columns>
</asp>

查看本文来源


  • 打印文档
  • 推荐好友
  • 返回顶部
  • 增大字体
  • 减少字体
关于本站 | 工作机会 | 合作网站 | 广告服务 | 市场合作| 联系我们 | 抽奖活动
版权所有: 武汉威俊科技有限公司 Copyright 2005-2007 www.ITCNW.COM All rights reserved