In a gridview, we can use <%#Eval%>
or <%#Bind%>
to output values from a database. What is the difference between them?
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.
eval is one way, bind is two way. If you aren't wanting to handle data posted back, eval will do the job.
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.
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.
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>
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?