GridView 绑定数据的常用指定格式。
2014-07-26 23:36
225 查看
形式 | 语法 | 结果 | 注释 |
数字 | {0:N2} | 12.36 | |
数字 | {0:N0} | 13 | |
货币 | {0:c2} | $12.36 | |
货币 | {0:c4} | $12.3656 | |
货币 | "¥{0:N2}" | ¥12.36 | |
科学计数法 | {0:E3} | 1.23E+001 | |
百分数 | {0:P} | 12.25% | P and p present the same. |
日期 | {0:D} | 2006年11月25日 | |
日期 | {0:d} | 2006-11-25 | |
日期 | {0:f} | 2006年11月25日 10:30 | |
日期 | {0:F} | 2006年11月25日 10:30:00 | |
日期 | {0:s} | 2006-11-25 10:30:00 | |
时间 | {0:T} | 10:30:00 |
1.要绑定的列如果单纯的是boundfiled类型的(如下)
<asp:BoundField DataField="sj" HeaderText="时间" ReadOnly="True" DataFormatString="{0:d}" />
显示出来的格式还是2006-11-25 0:00:00 为达到我们想要的效果
2.要绑定的列必须是模板列如下:这样才能看到我们想要看到的效果:2006-11-25
<asp:TemplateField HeaderText="时间">
<EditItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("sj", "{0:d}") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("sj", "{0:d}") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
相关文章推荐
- gridview 绑定多个格式相同的数据源(数据查询合并)
- GridView数据绑定控件的模版列时设置显示的格式
- asp.net<Web版> ---GridView 数据导出到excel表,系列问题<一>---导出的Excel文件格式与文件扩展名指定的格式不一致
- 常用过滤器:指定数据格式
- 数据绑定控件Repeater/GridView/DataList在前台显示正确的文本格式
- DataFormatString的格式 GridView数据常用格式化类型
- 数据绑定控件Repeater/GridView/DataList在前台显示正确的文本格式收藏
- 如何将数据绑定到gridview指定列中,终于解决啦~
- gridview绑定数据格式
- gridview绑定日期数据的格式
- GRIDVIEW绑定数据,显示“我是···”格式
- GridView 绑定数据显示段日期格式
- ASP.NET 数据绑定常用代码
- GridView中设置数据格式总结
- ASP.NET 数据绑定常用代码 (转)
- ASP.NET2.0中给GridView动态添加模板列并自动绑定数据
- GridView的两种数据绑定方式对分页的影响
- GridView动态绑定数据、编辑、修改、删除及分页功能
- 怎样在gridview和datalist之类的绑定控件里控制显示 数据省略?
- GridView 数据绑定列的格式化输出