• GridView 绑定数据的常用指定格式。


    形式

    语法

    结果

    注释

    数字

    {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

     

    在GridView中操作的时候要注意以下的几个方面(以{0:d}为例)

    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>

  • 相关阅读:
    数据切分——Atlas介绍
    HDU 5015 233Matrix (构造矩阵)
    Wincc操作数据库SQLSERVER
    UIWebView 设置背景为透明
    29个你必须知道的Linux命令
    【读书笔记】iOS-UIWindow-WindowLevel
    linux下uart应用编程
    Java Web HelloWorld!
    手把手图文教你eclipse下如何配置tomcat
    Tomcat安装及配置教程
  • 原文地址:https://www.cnblogs.com/leeairw/p/3870784.html
Copyright © 2020-2023  润新知