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

  • 相关阅读:
    Python中所有的关键字
    关于selenium的8种元素定位
    对提示框的操作
    selenium+webservice进行百度登录
    MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk. Commands that may modify the data set are disabled...报错解决
    Vue中使用echarts
    npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142解决方法
    插入排序
    冒泡排序优化
    roject 'org.springframework.boot:spring-boot-starter-parent:XXX' not found 解决
  • 原文地址:https://www.cnblogs.com/chenmfly/p/5294770.html
Copyright © 2011-2022 走看看