• 本文介绍下,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. CSS之按钮过滤

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  2. python判断指定路径是否存在

    https://www.cnblogs.com/jhao/p/7243043.html

  3. jQuery-轮播图(友善滴滚动切换)

    线上实例:http://lgy.1zwq.com/slide/ [处理] 这里的图片滚动轮播,做了点小处理:当在第1页状态时,你点击第5页,图片的滚动是一张滑过,而不是从2-3-4-5(这种的多张滚动 ...

  4. grub2 windows版安装

    一.BIOS方式,grub2安装 查看磁盘情况 E:\grub-2.02-for-windows>wmic diskdrive list brief Caption DeviceID Model ...

  5. 在js中做数字字符串补0

    转自(http://blog.csdn.net/aimingoo/article/details/4492592) 通常遇到的一个问题是日期的“1976-02-03 HH:mm:ss”这种格式 ,我的 ...

  6. 1: 介绍Prism5.0 Introduction to the Prism Library 5.0 for WPF(英汉对照版)

     Prism provides guidance designed to help you more easily design and build rich, flexible, and easy- ...

  7. hdu 6038 Function

    Function Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total ...

  8. python3 快速排序

    思路 第一步:找到一个随机的数,一般都是第一个数,也就是left,递归中也用left,放到缓存中,专业叫 基准值,基准值是要放在中间的. 第二步:最左边空出一个位置就是索引left的位置,所以从右向左 ...

  9. LeetCode OJ:Search a 2D Matrix II(搜寻二维矩阵)

    Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the follo ...

  10. Java发送短信

    1.接口使用介绍 发送短信肯定需要使用第三方接口,Java本身是肯定不能直接发送短信的.第三方接口有很多,这里直接找个正规靠谱一点的学习一下 这里使用了中国网建(http://sms.webchine ...