zoukankan      html  css  js  c++  java
  • Eval

    2、 2.x简化Eval数据绑定语法

    <asp:Literal id="litEval1" runat="server" Text='<%Eval("userName")%>' />

    3、第二种方法的方法重载

    <%# Eval("userName") %>

    4、eval同时绑定两个值

    <%# Eval("userName") %>

    <%# Bind("Subject") %> //绑定字段
    <%# Container.DataItemIndex + 1%> //实现自动编号
    <%# DataBinder.Eval(Container.DataItem, "[n]") %>
    通常使用的方法(这三个性能最好)
    <%# DataBinder.Eval(Container.DataItem, "ColumnName") %>
    <%# DataBinder.Eval(Container.DataItem, "ColumnName", null) %>
    <%# DataBinder.Eval(Container, "DataItem.ColumnName", null) %>
    其他用法
    <%# ((DataRowView)Container.DataItem)["ColumnName"] %>
    <%# ((DataRowView)Container.DataItem).Row["ColumnName"] %>
    <%# ((DataRowView)Container.DataItem)["adtitle"] %>
    <%# ((DataRowView)Container.DataItem)[n] %>
    <%# ((DbDataRecord)Container.DataItem)[0] %>
    <%# (((自定义类型)Container.DataItem)).属性.ToString() %>//如果属性为字符串类型就不用ToString()了
    DataBinder.Eval用法范例
    <%# DataBinder.Eval(Container.DataItem, "IntegerValue", "{0:c}") %>
    格式化字符串参数是可选的。如果忽略参数,DataBinder.Eval 返回对象类型的值,

    //显示二位小数
    <%# DataBinder.Eval(Container.DataItem, "UnitPrice", "${0:F2}") %>

    //{0:G}代表显示True或False

    <asp:Image Width="12" Height="12" Border="0" runat="server"
    AlternateText='<%# DataBinder.Eval(Container.DataItem, "Discontinued", "{0:G}") %>'
    ImageUrl='<%# DataBinder.Eval(Container.DataItem, "Discontinued", "~/images/{0:G}.gif") %>' />

    //转换类型
    ((string)DataBinder.Eval(Container, "DataItem.P_SHIP_TIME_SBM8")).Substring(4,4)
    {0:d} 日期只显示年月日
    {0:yyyy-mm-dd} 按格式显示年月日
    {0:c} 货币样式
    <%#Container.DataItem("price","{0:¥#,##0.00}")%>
    <%# DataBinder.Eval(Container.DataItem,"Company_Ureg_Date","{0:yyyy-M-d}")%>
    Specifier Type Format Output (Passed Double 1.42) Output (Passed Int -12400)
    c Currency {0:c} $1.42 -$12,400
    d Decimal {0:d} System.FormatException -12400
    e Scientific {0:e} 1.420000e+000 -1.240000e+004
    f Fixed point {0:f} 1.42 -12400.00
    g General {0:g} 1.42 -12400
    n Number with commas for thousands {0:n} 1.42 -12,400
    r Round trippable {0:r} 1.42 System.FormatException
    x Hexadecimal {0:x4} System.FormatException cf90

    {0:d} 日期只显示年月日
    {0:yyyy-mm-dd} 按格式显示年月日

    样式取决于 Web.config 中的设置
    {0:c} 或 {0:£0,000.00} 货币样式 标准英国货币样式
    <system.web>

    </system.web>
    显示为 £3,000.10

    {0:c} 或 string.Format("{0:C}", price); 中国货币样式
    <system.web>

    </system.web>
    显示为 ¥3,000.10

    {0:c} 或 string.Format("{0:C}", price); 美国货币样式
    <system.web>

    </system.web>
    显示为 $3,000.10

  • 相关阅读:
    【动画技巧】在Flash中自定义鼠标外观
    【动画技巧】GIF动画转SWF小技巧
    SQL Server 2008空间数据应用系列十一:提取MapInfo地图数据中的空间数据解决方案
    SQL Server 2008空间数据应用系列十:使用存储过程生成GeoRSS聚合空间信息
    jQuery的模板与数据绑定插件
    ASP.NET MVC 入门5、View与ViewData
    一个jQuery写的虚拟键盘
    ASP.NET MVC 入门4、Controller与Action
    使用XML文件来动态配置ASP.NET MVC的Route规则
    ASP.NET MVC 入门9、Action Filter 与 内置的Filter实现(介绍)
  • 原文地址:https://www.cnblogs.com/chenmfly/p/5294770.html
Copyright © 2011-2022 走看看