惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - Franky
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
有赞技术团队
有赞技术团队
aimingoo的专栏
aimingoo的专栏
WordPress大学
WordPress大学
人人都是产品经理
人人都是产品经理
酷 壳 – CoolShell
酷 壳 – CoolShell
L
LangChain Blog
Blog — PlanetScale
Blog — PlanetScale
阮一峰的网络日志
阮一峰的网络日志
Microsoft Azure Blog
Microsoft Azure Blog
云风的 BLOG
云风的 BLOG
Google DeepMind News
Google DeepMind News
T
The Blog of Author Tim Ferriss
G
Google Developers Blog
Hugging Face - Blog
Hugging Face - Blog
Y
Y Combinator Blog
D
DataBreaches.Net
Engineering at Meta
Engineering at Meta
MyScale Blog
MyScale Blog
大猫的无限游戏
大猫的无限游戏
S
SegmentFault 最新的问题
The GitHub Blog
The GitHub Blog
Recent Announcements
Recent Announcements

博客园 - Titans

一个想嫁有钱人的女孩得到的回复 ASP.NET 中执行 URL 重写 - Titans 在 ASP.NET 中执行 URL 重写 国外C#开源系统一览表 五蕴皆空 项目管理一些体会 职场好人缘的26个细节 试译Fowler的《更多企业应用架构模式》稿 C# String Library ASP.NET 2.0页面框架的几处变化 ADO.NET 2.0 大批量数据操作和多个动态的结果集 ASP.NET 2.0 中收集的小功能点 战将宣言 Titans:小天使 日历控件源码开放--适用于ASP.NET 1.1 爱的距离 华为的冬天 - Titans - 博客园 每件事都有它的道理 搜索引擎优化排名方法
小tips:asp.net 2.0中在gridview中使用DataFromatString
Titans · 2006-09-25 · via 博客园 - Titans

可能之前不少朋友也已经试过,但我是今天才遇到这个问题,翻查资料后才解决。主要是
在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://www.cnblogs.com/jackyrong/archive/2006/08/28/488282.html