In a gridview, we can use <%#Eval%> or <%#Bind%> to output values from a database. What is the difference between them?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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?
Method 2
eval is one way, bind is two way. If you aren’t wanting to handle data posted back, eval will do the job.
Method 3
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.
Method 4
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.
Method 5
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>
Method 6
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.
Method 7
I think there is no difference in both. We can use Eval as well as Bind for all operations like insert, update and delete as well as select.
Because I have work with both and it works fine in both scenarios.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0