• 本文介绍下,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. Java的 final 关键字

    本文主要探讨Java final 关键字修饰变量时的用法. !!!!文末有彩蛋!!!! 1.修饰类 当用final修饰一个类时,表明这个类不能被继承.也就是说,如果一个类你永远不会让他被继承,就可以用 ...

  2. Hive -hivevar 参数传递

    命令行模式,或者说目录模式,可以使用hive 执行命令. 选项说明: -e : 执行短命令 -f :  执行文件(适合脚本封装) -S : 安静模式,不显示MR的运行过程 -hivevar : 传参数 ...

  3. svn diff color

    大致有两种方式: 1,在bashrc中添加如下脚本 svndiff() { svn diff "${@}" | colordiff } 2,修改svn的配置文件 $ vim ~/. ...

  4. 转载:Javascript面向对象编程原理 -- 理解对象

    源地址:http://www.html-js.com/article/1717 虽然JavaScript中已经自带了很多内建引用类型,你还是会很频繁的需要创建自己的对象.JavaScript编程的很大 ...

  5. 阅读《大型网站技术架构:核心原理与案例分析》第五、六、七章,结合《XXX重大技术需求征集系统》,列举实例分析采用的可用性和可修改性战术,将上述内容撰写成一篇1500字左右的博客阐述你的观点。

    这三章主要讲述的是网站的可用性.伸缩性和可扩展性. 首先,网站的可用性描述网站可有效访问的特性,相比于网站的其他非功能特性,网站的可用性更容易引起人们的注意,尤其是大型网站的可用性,如果大公司的网站出 ...

  6. http://blog.csdn.net/milton2017/article/details/54406482

    转自:python 把几个DataFrame合并成一个DataFrame——merge,append,join,conca http://blog.csdn.net/zutsoft/article/d ...

  7. Verilog HDL Test Bench

    As digital systems becomes more complex,it becomes increasingly important to verify the functionalit ...

  8. C++多线程2.beginthread

    C++ 多线程2 beginthread 启动线程知识 20131021 Reference: http://blog.csdn.net/laoyang360/article/details/7720 ...

  9. kvm虚拟主机安装速度很慢

    在c6220 II上部署虚拟化遇到的问题: 1.部署完kvm后,安装虚拟主机的过程非常缓慢,但是最终能成功 原因:宿主机BIOS的virtualization technology设置为Disable ...

  10. 项目提交到github的忽略文件

    1.在工作区的.gitignore文件中配置如下: # Built application files*.apk*.ap_ # Files for the Dalvik VM*.dex # Java ...