zoukankan      html  css  js  c++  java
  • 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} 货币样式

    aspx中:
    <asp:TemplateField HeaderText="是否通过">
        <ItemTemplate>
            <asp:Label ID="Label6" runat="server" Text='<%# (int)DataBinder.Eval(Container.DataItem, "scores") >= (int)DataBinder.Eval(Container.DataItem, "passscore") ? "及格" : "不及格" %>' ForeColor='<%# (int)DataBinder.Eval(Container.DataItem, "scores") >= (int)DataBinder.Eval(Container.DataItem, "passscore") ? System.Drawing.Color.Green : System.Drawing.Color.Red %>'>
            </asp:Label>
        </ItemTemplate>
        <ItemStyle Width="15%" />
    </asp:TemplateField>

    or

    aspx.cs中
     protected void grdMovies_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                decimal boxOfficeTotals = (decimal)DataBinder.Eval(e.Row.DataItem, "BoxOfficeTotals");
                if (boxOfficeTotals > 300000000)
                    e.Row.BackColor = System.Drawing.Color.Yellow;
            }
        }

  • 相关阅读:
    正则表达式30分钟入门教程
    Literal控件用法
    用asp.net 2.0实现网站二级域名
    IIS7 asp.net URL重写配置
    用VS2008开发Ajax网站需要注意
    C#中的equals与==的比较,赋加compareto
    nvchar(50)与Substring(0,50)的理解
    利用Mircosoft URLRewriter.dll实现asp.net页面伪静态
    .NET命名规范中文版
    iframe动态改变src的测试
  • 原文地址:https://www.cnblogs.com/Caesar/p/1016627.html
Copyright © 2011-2022 走看看