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>

  • 相关阅读:
    jsp mysql 实现客户端简单分页查询
    jsp mysql 实现客户端简单数据的修改和删除
    jsp 简单把数据库数据,展示在网页
    XML当做数据库,完成增删查
    xml的增删查 dom的增改查 复杂注释
    修改目录下所有文件时间
    打开调试模式
    强化学习笔记4:无模型预测 model-free prediction
    强化学习笔记6:值函数估计Value function Approximation
    Declarative Pipeline语法介绍
  • 原文地址:https://www.cnblogs.com/cuihongyu3503319/p/1234916.html
Copyright © 2011-2022 走看看