• 本文介绍下,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. 使用@media screen解决移动web开发的多分辨率问题

    当今移动设备的发展已经越来越迅速,移动web开发的需求也越来越多多.许多大平台.大门户都纷纷推出了自己的移动web版网站. 随着移动设备飞速的发展,移动产品的屏幕规格越来越多.从几年前的320×240 ...

  2. ES5下的React

    按照官方推荐的思路,React使用标准的ES6标准的语法.比如说创建一个类: class Greeting extends React.Component { render() { return &l ...

  3. Python打包分发工具setuptools简介(转)

    作为Python标准的打包及分发工具,setuptools可以说相当地简单易用.它会随着Python一起安装在你的机器上.你只需写一个简短的setup.py安装文件,就可以将你的Python应用打包. ...

  4. tarball安装GnuPG (gpg) 2.2.10

    https://www.gnupg.org/download/ mac 方式一:推荐 mac $ brew install gpg pinentry pinentry-mac $ echo " ...

  5. iptables详解(12):iptables动作总结之一

    前文一直在介绍iptables的匹配条件,并没有对动作进行过总结,那么此处,我们就来总结一下iptables中的动作. 之前的举例中已经用到了一些常用动作,比如ACCEPT.DROP.REJECT等. ...

  6. dropload.js 上滑加载,下拉刷新

    https://github.com/ximan/dropload dropload a javascript implementation of pull to refresh and up to ...

  7. window.history.go(-1);

    history是你浏览过的网页的url(简单的说就是网址)的集合,也就是你的浏览器里的那个历史记录.它在js里是一个内置对象,就跟document一样,它有自己的方法,go就是其中一个. 这个方法的参 ...

  8. redisAPI整理

    全局命令 1.查看所有键 keys * 2.键总数 dbsize 3.检查键是否存在 exists key 4.删除键 del key del key1 key2 key3 5.键过期 expire ...

  9. hdu4453

    题解: splay模板 删除,翻转等等 代码: #include<cstdio> #include<cstring> #include<cmath> #includ ...

  10. 让nodejs在iis上运行

    node在IIS上运行的好处: Tomasz的回答是我见过最棒的: 使用iisnode模块在IIS中托管node.js应用程序来取代自托管node.exe进程的优势在于: · 进程管理. Iisnod ...