| Author: Deepa 18 Jul 2008 | Member Level: Diamond | Rating: Points: 6 |
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.
|
| Author: UltimateRengan 18 Jul 2008 | Member Level: Diamond | Rating: Points: 1 |
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
More reference login to:- http://bytes.com/forum/thread623528.html http://www.tech-archive.net/Archive/DotNet/microsoft.public.dotnet.general/2007-03/msg00853.html
UltimateRengan nathan.rengan@gmail.com Trichy-Rider Group
|
| Author: lalitha 18 Jul 2008 | Member Level: Gold | Rating: Points: 6 |
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. 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.
Using the Bind Method
The Bind method has some similarities to the Eval method, but there are significant differences. Although you can retrieve the values of data-bound fields with the Bind method, as you can with the Eval method, the Bind method is also used when data can be modified. In ASP.NET, data-bound controls such as the GridView, DetailsView, and FormView controls can automatically use the update, delete, and insert operations of a data source control. For example, if you have defined SQL Select, Insert, Delete, and Update statements for your data source control, using Bind in a GridView, DetailsView, or FormView control template enables the control to extract values from child controls in the template and pass them to the data source control. The data source control in turn performs the appropriate command for the database. For this reason, the Bind function is used inside the EditItemTemplate or InsertItemTemplate of a data-bound control. The Bind method is typically used with input controls such as the TextBox control rendered by a GridView row in edit mode. When the data-bound control creates these input controls as part of its own rendering, it can extract the input values. The Bind method takes the name of a data field to associate with the bound property.
|
| Author: chandramohan 18 Jul 2008 | Member Level: Gold | Rating: Points: 1 |
How ASP.NET databinding deals with Eval() and Bind() statements A recent question on one of our internal mailing lists asked where the definition for the Bind() method is located in ASP.NET. The asker had located the definition of the Eval() method on the TemplateControl class, but the Bind() method was nowhere to be found, even using Reflector.
If you're familiar with databinding in ASP.NET 2.0, you probably know that for read-only values such as Labels you can use the Eval() statement, and for read-write values such as TextBoxes (also known as "two-way databinding") you can use the Bind() statement. Where does that Bind() statement come from?
To the surprise of many readers, there isn’t a bind method in ASP.NET! When ASP.NET parses your file and sees you're using a databinding expression (in the angle-bracket-percent-pound format, "<%# %>") it has special-case code to parse for the Bind syntax and generates some special code for it. When you use <%# Bind("Name") %> it's not a real function call. If ASP.NET parses the code and detects a Bind() statement, it splits the statement into two parts. The first part is the one-way databinding portion, which ends up being just a regular Eval() call. The second part is the reverse portion, which is typically some code along the lines of "string name = TextBox1.Text" that grabs the value back out from where it was bound.
Non-Bind() databinding statements are literal code (we use CodeSnippetExpressions in CodeDom), so arbitrary code in the language of your choice is allowed. However, because ASP.NET has to parse Bind() statements, two-way databinding doesn’t support anything other than Bind(). For example, the following syntax is invalid because it tries to invoke arbitrary code and use Bind() at the same time: <%# FormatNameHelper(Bind("Name")) %> The only formats supported in two-way databinding are Bind("field") and Bind("field", "format string {0}"). There are some very minor variations of these syntax examples, such as allowing use of single quotes and not just double quotes. Since some languages supported by ASP.NET favor one format over the other, we have to support both formats, even though the language you're using may support only one.
----------------
|
| Author: Ratheesh 18 Jul 2008 | Member Level: Gold | Rating: Points: 1 |
Eval function is used to define one-way (read-only) binding - used for read-only values such as Labels, Literals
Eval method belongs to the TemplateControl class and has to override methods TemplateControl.Eval(field_name) and TemplateControl.Eval(field_name, format)Bind function is used for two-way (updatable) binding - used for read-write values such as TextBoxes
There isn’t a bind method in ASP.NET! When ASP.NET parses your file and sees you're using a databinding expression (in the angle-bracket-percent-pound format, "<%# %>") it has special-case code to parse for the Bind syntax and generates some special code for it. When you use <%# Bind("Name") %> it's not a real function call.
If ASP.NET parses the code and detects a Bind() statement, it splits the statement into two parts.
1) The first part is the one-way databinding portion, which ends up being just a regular Eval() call. 2) The second part is the reverse portion, which is typically some code along the lines of "string name = TextBox1.Text" that grabs the value back out from where it was bound.
The only formats supported in two-way databinding are Bind("field") and Bind("field", "format string {0}"). There are some very minor variations of these syntax examples, such as allowing use of single quotes and not just double quotes.
|