What is the difference between Eval and bind methods in asp.net
4 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Rajkiran SwainRank #165 · 14.4K reputationPosted Aug 22, 2017, 6:10 AM EDT
+3
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.
Eval is a one way binding.
Bind is two way binding.
If you bind a value using Eval, it is like a read only. You can only view the data.
If you bind a value using Bind, and if you do some change on the value it will reflect on the database also
For read-only controls they are the same. For 2 way databinding,
using a datasource in which you want to update, insert, etc with
declarative databinding, you'll need to use Bind.
Imagine for example a GridView with a ItemTemplate and EditItemTemplate. If you use Bind or Eval in the ItemTemplate, there will be no difference. If you use Eval in the EditItemTemplate, the value will not be able to be passed to the Update method of the DataSource that the grid is bound to.
Here is more discussion on Eval and Bind have a look
Eval is a protected method defined on the TemplateControl class, from which the Page class is derived.
Bind is a new ASP.NET 2.0 databinding keyword. It's not a method of any specific class.
Eval is used for unidirectional (readonly) data binding, while Bind is for bi-directional (editable) databinding.
ASP.NET supports a hierarchical data-binding model that creates bindings between server control properties and data sources. Almost any server control property can be bound against any public field or property on the containing page or on the server control's immediate naming container.
Data-binding expressions use the Eval and Bind methods to bind data to controls and submit changes back to the database. The Eval method is a static (read-only) method that takes the value of a data field and returns it as a string. The Bind method supports read/write functionality with the ability to retrieve the values of data-bound controls and submit any changes made back to the database.
You can bind to XML data from an XmlDataSource control using the XPath and XPathSelect methods, as well as the XPathBinder class.
Rajkiran SwainRank #165 · 14.4K reputationPosted Aug 22, 2017, 6:10 AM EDT
Priyanka SinghRank #1,215 · 1.5K reputationPosted Jun 30, 2019, 10:18 PM EDT
For read-only controls they are the same. For 2 way databinding, using a datasource in which you want to update, insert, etc with declarative databinding, you'll need to use
Bind.Imagine for example a GridView with a
ItemTemplateandEditItemTemplate. If you useBindorEvalin theItemTemplate, there will be no difference. If you useEvalin theEditItemTemplate, the value will not be able to be passed to theUpdatemethod of theDataSourcethat the grid is bound to.Rajanikant HawaldarRank #110 · 20.3K reputationPosted Jun 30, 2019, 10:23 PM EDT
Sivakumar KonetiRank #1,557 · 1K reputationPosted Jul 1, 2019, 6:47 PM EDT
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts