Eval和Bind之间的区别

时间:2011-07-07 11:18:05

标签: c# asp.net controls

  

可能重复:
  Understanding asp.net Eval() and Bind()

    <asp:DataList ID="DataList1" runat="server" DataKeyField="CustomerID" 
    DataSourceID="SqlDataSource1">
    <ItemTemplate>
        CustomerID:
        <asp:Label ID="CustomerIDLabel" runat="server" 
            Text='<%# Eval("CustomerID") %>' />

    </ItemTemplate>
</asp:DataList>

Eval和Bind之间的区别是什么?

4 个答案:

答案 0 :(得分:3)

Eval方法评估数据绑定控件(如GridView,DetailsView和FormView控件)模板中的后期绑定数据表达式,Bind方法通常用于输入控件,例如GridView行呈现的TextBox控件在编辑模式。

答案 1 :(得分:2)

在询问之前,您有searched的答案吗?

  

Eval是一个受保护的方法   TemplateControl类,从中   Page类派生出来。绑定是一个   新的ASP.NET 2.0数据绑定关键字。   这不是任何具体的方法   类。

     

Eval用于单向   (readonly)数据绑定,而Bind是   用于双向(可编辑)   数据绑定。

答案 2 :(得分:1)

Eval以只读方式使用...所以只获取数据并显示它。 Bind是两种方式数据绑定的用户......

答案 3 :(得分:1)

这意味着标签CustomerIDLabel将从数据库中获取值,其中列名为CustomerID