• 本文介绍下,asp.net编程中有关DataBinder.Eval的用法,学习下asp.net DataBinder.Eval的用法,有需要的朋友参考下。

      代码示例

      :<%# 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
       <ItemTemplate>
      <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") %>' />
      </ItemTemplate>

      转换类型: ((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 中的设置,分享三个示例代码。
      1,{0:c}   或 {0:£0,000.00} 货币样式   标准英国货币样式

      代码示例:

      <system.web>
      <globalization requestEncoding="utf-8" responseEncoding="utf-8" culture="en-US" uiCulture="en-US" />
      </system.web>
      显示为 £3,000.10
      2,{0:c}   或 string.Format("{0:C}", price); 中国货币样式

       代码示例:

      <system.web>
      <globalization requestEncoding="utf-8" responseEncoding="utf-8" culture="zh-cn" uiCulture="zh-cn" />
      </system.web>
      显示为 ¥3,000.10
      3,{0:c}   或 string.Format("{0:C}", price); 美国货币样式

      代码示例:

      <system.web>
      <globalization requestEncoding="utf-8" responseEncoding="utf-8" />
      </system.web>
      显示为 $3,000.10

DataBinder.Eval的正确使用的更多相关文章

  1. ASP.NET中的Eval与DataBinder.Eval()方法

    1.bind是一种双向数据绑定,有数据源时才会有改变. 2..net1.x版本中有DataBinder(Container.DataItem,"数据项")  单向数据绑定 .net ...

  2. Eval()和DataBinder Eval(Container DataItem,)的区别及用法

        ASP.NET 2.0改善了模板中的数据绑定操作把v1.x中的数据绑定语法DataBinder.Eval(Container.DataItem, fieldname)简化为Eval(fiel ...

  3. Asp服务器控件(HyperLink、Button) 绑定后台参数 DataBinder.Eval

    HyperLink动态绑定参数 <asp:HyperLink id="MbCenterHLnk" runat="server" Text='会员中心' T ...

  4. Eval与DataBinder.Eval的区别

    DataBinder.Eval的基本格式 DataBinder.Eval(Container.DataItem,"XXX","{0}") <%# Data ...

  5. DataBinder.Eval值的判断

    原文发布时间为:2009-04-10 -- 来源于本人的百度文章 [由搬家工具导入] 问:如何对<%# DataBinder.Eval(Container.DataItem,"Ly_R ...

  6. C# Eval()和Bind()

    Eval( " ")和Bind( " ") 这两种一个单向绑定,一个双向绑定,bind是双向绑定,但需数据源支持ASP.NET   2.0改善了模板中的数据绑定 ...

  7. C# Eval在aspx页面中的用法及作用

    Eval( " ")和Bind( " ") 这两种一个单向绑定,一个双向绑定,bind是双向绑定,但需数据源支持 ASP.NET 2.0改善了模板中的数据绑定操 ...

  8. [转]C# Eval在asp.net中的用法及作用

    原文链接:http://www.cnblogs.com/Mr_JinRui/archive/2010/07/06/1772129.html Eval( " ")和Bind( &qu ...

  9. Web页面报错: Eval()、XPath() 和 Bind() 这类数据绑定方法只能在上下文中使用

    可以使用string.formt来避免出错. 如: <%# Convert.ToInt32(DataBinder.Eval(Container.DataItem, "Status&qu ...

随机推荐

  1. python中如何剔除字符串

    问题: 过滤用户输入中前后多余的空白字符 ‘    ++++abc123---    ‘ 过滤某windows下编辑文本中的’\r’: ‘hello world \r\n’ 去掉文本中unicode组 ...

  2. python 函数、模块、包及import导入方法

    https://www.cnblogs.com/lijunjiang2015/p/7812996.html

  3. Qt5全局热键-QxtGlobalShortcut

    最近做一个项目需要注册全局热键,在网上搜索发现有个第三方库 libqxt 中给出一个比较好的跨平台的解决方案,就是 QxtGlobalShortcut. 但是编译过程中发现这个库用到的QAbstrac ...

  4. 3.spring cloud eureka 高可用

    1.目的 防止某一台服务器宕机 通常通过多台EUREKA来为客户端进行注册,客户也进行注册 2.开启三台EUREKA 三天EUREKA分别对应端口 8761 8762 8763 配置文件如下 EURE ...

  5. 004PHP基础知识——数据类型(一)

    <?php /* * 数据类型(一) * 标量类型:整型(int) 浮点型(float) 字符串型(string) 布尔型(boolean) * 复合类型:数组(array) 对象(object ...

  6. linux oracle11g 数据 导入到10g数据库

    说明: 原用户名和密码:test/test  目标用户名和密码:test01/test 11G 服务器: 1.创建dmp文件存储目录 # mkdir -p /tmp/backup # sqlplus ...

  7. iOS 数组集合操作(交集,并集,差集,子集)

    1.求数组的 交集,并集,差集 NSArray *array1 = @[@"1",@"2",@"3"]; NSArray *array2 = ...

  8. SpringInAction-- 配置Profile Bean

    Profile Bean 使用场景描述: 在开发软件的时候,在数据库方面,往往不是一个库就能解决的,一般分为开发库.测试库.生产库,在这些库设置链接的时候,也会配置其对应的数据. 现有一种方式,就是单 ...

  9. LVS模式二:隧道模式(Tun)

    一.IP隧道(IP Tunneling) ip隧道是一个将ip报文封装到另一个ip报文的技术,这可以使得目标为一个ip地址的数据报文被封装和转发到另一个ip地址.ip隧道技术也成为ip封装技术.    ...

  10. Mac怎么安装Windows10

    当前  Windows10 系统的预览版已经出来,对于新系统感兴趣的不只是使用 PC 电脑的用户,还有一些是当前正在使用 Mac 系统的用户.其实安装 Windows 10 与以前安装 Windows ...