Tuesday, 20 March 2012

Difference between Eval() And Bind() Methods

1 )  Eval is used for unidirectional (readonly) data binding, while Bind is for bi-directional (editable) databinding

2)  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.

3) 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

4)  The Eval method evaluates late-bound data expressions in the templates of data-bound controls such as the GridView, DetailsView, and FormView controls. At run time, the Eval method calls the Eval method of the DataBinder object, referencing the current data item of the naming container. The naming container is generally the smallest part of the data-bound control that contains a whole record, such as a row in a GridView control. You can therefore use the Eval method only for binding inside templates of a data-bound control.
5)  The Eval method takes the name of a data field and returns a string containing the value of that field from the current record in the data source. You can supply an optional second parameter to specify a format for the returned string. The string format parameter uses the syntax defined for the Format method of the String class.

No comments:

Post a Comment