What's the difference between <#eval and <#bind in asp.net

前端 未结 7 825
天命终不由人
天命终不由人 2020-12-31 01:09

In a gridview, we can use <%#Eval%> or <%#Bind%> to output values from a database. What is the difference between them?

相关标签:
7条回答
  • 2020-12-31 01:34

    The main difference between eval and bind is eval is read only, we can't change on database thing eval.

    While using bind we can appply some change.

    If you aren't wanting to handle data posted back, eval will do the job easily.

    0 讨论(0)
  • 2020-12-31 01:40

    eval is one way, bind is two way. If you aren't wanting to handle data posted back, eval will do the job.

    0 讨论(0)
  • 2020-12-31 01:48

    Eval and Bind functions are used to bind data from database to controls present inside DataBound controls like GridView, DetailsView, Repeater, DataList, etc.

    The difference between Eval and Bind is that Eval function is used to bind data to control inside a DataBound control, but it cannot update the values back to the database.

    On the other hand, Bind function can be used to bind data to control inside a DataBound control and also it can update the values back to the database.

    0 讨论(0)
  • 2020-12-31 01:50

    The main difference between eval and bind is eval is read only, we can't change on database thing eval.

    While using bind we can appply some change to the database.

    0 讨论(0)
  • 2020-12-31 01:54

    as they said Eval is one way and Bind is two way but one more important difference Bind must be assigned to a property of server side control (runat="server") while you can assign Eval to server side or client side control

    <asp:ListView ID="listview1" runat="server">
        <ItemTemplate>
             <%--you can do this--%>
             <asp:Label ID="label1" runat="server" Text="<%#Bind('xx')  %>"></asp:Label>
             <%--you can do this--%>
             <asp:Label ID="label2" runat="server" Text="<%#Eval('xx')  %>"></asp:Label>
             <div>
             <%--WILL CAUSE AN ERROR--%>
                 "<%#Bind('xx')  %>" 
             <%--you can do this--%>
                 "<%#Eval('xx')  %>" 
             </div>
        </ItemTemplate>
    </asp:ListView>
    
    0 讨论(0)
  • 2020-12-31 01:57

    Eval does one-way binding; Bind is two-way.

    If you bind a value using Eval, it is read-only. You can only view the data.

    If you bind a value using Bind, changes to values will be reflected in the database as well.

    You can refer to this similar post here on stack overflow: What is the difference between <%# Bind("") %> and <%# Eval("") %> in ASP.NET?

    0 讨论(0)
提交回复
热议问题