zoukankan      html  css  js  c++  java
  • Eval和Bind的区别(不是其他人说的那个,突然发现的)

           
    IList<A> As = GetAs();
    GridViewList.DataSource = As;
    GridViewList.DataBind();

    其中B是自定义的一个类是A类中的一个属性,Name是B类中的一个属性绑定GridViewList上的As是A类的一个泛型集合
    下面的绑定Eval可以正确现实,但是换成Bind报错,为什么不清楚
    <asp:TemplateField HeaderText="Page Title">
    <ItemTemplate>
    <asp:Label ID="Label1" runat="server" Text='<%# Eval("B.Name") %>'></asp:Label>
    </ItemTemplate>
    </asp:TemplateField>

    <asp:TemplateField HeaderText="Page Title">
    <ItemTemplate>
    <asp:Label ID="Label1" runat="server" Text='<%# Bind("B.Name") %>'></asp:Label>
    </ItemTemplate>
    </asp:TemplateField>


    public class A
    {
        private B _b;
        public B B
        {
            get
            {
                if (_b == null)
                {
                    _b = new B();
                }
                return _b;
            }
            set
            {
                _b = value;
            }
        }
    }
    public class B
    {
        private string _name;
        public string Name
        {
            get
            {
                return _name;
            }
            set
            {
                _name = value;
            }
        }
    }

    二.

    <asp:TemplateField HeaderText="EntryDate">
                                        <ItemTemplate>
                                            <asp:Label ID="LabelEntryDate" runat="server" Text='<%#Convert.ToDateTime(Eval("EntryDate")).ToString("yyyy-MM-dd HH:mm:ss") %>'></asp:Label>
                                        </ItemTemplate>
                                    </asp:TemplateField>

    用下面就报错

    <asp:TemplateField HeaderText="EntryDate">
                                        <ItemTemplate>
                                            <asp:Label ID="LabelEntryDate" runat="server" Text='<%#Convert.ToDateTime(Bind("EntryDate")).ToString("yyyy-MM-dd HH:mm:ss") %>'></asp:Label>
                                        </ItemTemplate>
                                    </asp:TemplateField>

  • 相关阅读:
    单独的数字
    设计模式之原型模式
    设计模式之策略模式
    设计模式之单例模式
    泛型入门
    iOS中关于.pch的新建与配置问题
    iOS开发中遇到的头文件找不到的问题解决办法
    iOS中NSJSONSerialization的使用 小记
    6.线程、进程、协程基础篇
    5.装饰器进阶篇
  • 原文地址:https://www.cnblogs.com/cuihongyu3503319/p/1234916.html
Copyright © 2011-2022 走看看