Differences between Bind and Eval in C #

Source: Internet
Author: User

The data binding expression is included in<% #And
%>Separator, and use
EvalAndBindFunction.
Eval
A function is used to define one-way (read-only) binding.BindA function is used to define bidirectional (updatable) binding.
Besides
EvalAndBindYou can also call<% #And%>
Any common code within the delimiter to execute the code During page processing and return a value.

The Eval method is a static (read-only) method that uses the value of a data field as a parameter and returns it as a string. Bind
The read/write function is supported to retrieve the value of the data-bound control and submit any changes to the database. The eval () method uses reflection to perform post-Binding Calculations at runtime. Therefore, compared with the standard ASP. NET data binding method, this causes a significant reduction in performance. It is generally used to format strings when binding. Use this method as few as possible in most cases

Use the Eval Method

EvalMethod to compute data binding controls (such
GridView,DetailsViewAnd
FormViewControls. At runtime,EvalMethod call
The Eval method of the DataBinder object and reference the current data item of the named container. A naming container is usually the smallest component of a data binding control that contains a complete record, such
GridViewControl. Therefore, you can only bind data to the template of the control.Eval
Method.

Eval
The method uses the name of a data field as a parameter and returns a string containing the value of this field from the current record of the data source. The second parameter can be provided to specify the format of the returned string. this parameter is optional. The string format parameter is
The Format method definition syntax of the String class.

Bind Method

BindMethod andEvalMethods have some similarities, but there are also great differences. Although it can be used like
EvalSame MethodBind
Method to retrieve the value of the data binding field, but when the data can be modified, you still need to useBindMethod.

In ASP. NET, data is bound to controls (suchGridView,DetailsViewAnd
FormViewControls) automatically use the data source controls to update, delete, and insert data. For example, if you have defined an SQL
Select, Insert, Delete, and Update statements
GridView,DetailsViewOr
FormViewIn the control TemplateBind
The control can extract values from the Child control in the template and pass these values to the data source control. The data source control then executes appropriate database commands. For this reason
EditItemTemplateOrInsertItemTemplateTo use
BindFunction.

BindThe method is usually used with the input control, for exampleGridViewThe
TextBox Control. When the data binding control creates these input controls as a part of its own rendering, this method can extract the input value.

BindThe data field name is used as a parameter to associate with the bound property.

Explicitly call the DataBind Method

One scenario is to use the DataSource property (insteadPerformanceid
Property) When you bind a control to a data source control. In this case, you need to explicitly callDataBind
To bind and parse data.
Another scenario is when you need to manually refresh the data in the data binding control.

The data binding expression is included in<% #And
%>Separator, and use
EvalAndBindFunction.
Eval
A function is used to define one-way (read-only) binding.BindA function is used to define bidirectional (updatable) binding.
Besides
EvalAndBindYou can also call<% #And%>
Any common code within the delimiter to execute the code During page processing and return a value.

The Eval method is a static (read-only) method that uses the value of a data field as a parameter and returns it as a string. Bind
The read/write function is supported to retrieve the value of the data-bound control and submit any changes to the database. The eval () method uses reflection to perform post-Binding Calculations at runtime. Therefore, compared with the standard ASP. NET data binding method, this causes a significant reduction in performance. It is generally used to format strings when binding. Use this method as few as possible in most cases

Use the Eval Method

EvalMethod to compute data binding controls (such
GridView,DetailsViewAnd
FormViewControls. At runtime,EvalMethod call
The Eval method of the DataBinder object and reference the current data item of the named container. A naming container is usually the smallest component of a data binding control that contains a complete record, such
GridViewControl. Therefore, you can only bind data to the template of the control.Eval
Method.

Eval
The method uses the name of a data field as a parameter and returns a string containing the value of this field from the current record of the data source. The second parameter can be provided to specify the format of the returned string. this parameter is optional. The string format parameter is
The Format method definition syntax of the String class.

Bind Method

BindMethod andEvalMethods have some similarities, but there are also great differences. Although it can be used like
EvalSame MethodBind
Method to retrieve the value of the data binding field, but when the data can be modified, you still need to useBindMethod.

In ASP. NET, data is bound to controls (suchGridView,DetailsViewAnd
FormViewControls) automatically use the data source controls to update, delete, and insert data. For example, if you have defined an SQL
Select, Insert, Delete, and Update statements
GridView,DetailsViewOr
FormViewIn the control TemplateBind
The control can extract values from the Child control in the template and pass these values to the data source control. The data source control then executes appropriate database commands. For this reason
EditItemTemplateOrInsertItemTemplateTo use
BindFunction.

BindThe method is usually used with the input control, for exampleGridViewThe
TextBox Control. When the data binding control creates these input controls as a part of its own rendering, this method can extract the input value.

BindThe data field name is used as a parameter to associate with the bound property.

Explicitly call the DataBind Method

One scenario is to use the DataSource property (insteadPerformanceid
Property) When you bind a control to a data source control. In this case, you need to explicitly callDataBind
To bind and parse data.
Another scenario is when you need to manually refresh the data in the data binding control.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.