Introduction:
The data binding expression is included in the <% # And %> delimiters and uses EVAl and bind functions. EVThe Al function is used to define one-way (read-only) binding. The BIND function is used to define bidirectional (updatable) binding. Besides calling EV in a data binding expressionIn addition to data binding, the Al and bind methods can also call any common code within the <% # And %> delimiters to execute the code During page processing and return a value.
When the databind method of the control or page class is called, the data binding expression is parsed. Some controls, such as the gridview, detailsview, and formview controls, automatically parse the data binding expression during the prerender event of the control and do not need to explicitly call the databind method.
Use EVAl Method
EVThe Al method can calculate the post-bound data expression in the template of the data binding control (such as the gridview, detailsview, and formview controls. At runtime, EVThe Al method calls the ev of the databinder objectAnd reference the current data item of the container. A naming container is usually the smallest component of a data binding control that contains a complete record, such as a row in the gridview control. Therefore, you can only bind eV to the template of the data-bound control.Al method.
EVThe Al 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. String format parameters are defined using the format method of the string class.
Bind Method
Bind METHOD AND EVThe Al method has some similarities, but there are also great differences. Although it can be like using EVThe Al method uses the bind method to retrieve the value of the data-bound field, but the bind method must be used when the data can be modified.
In ASP. NET, data binding controls (such as the gridview, detailsview, and formview controls) can automatically use the update, delete, and insert operations of data source controls. For example, if you have defined SQL select, insert, delete, and update statements for the data source control, you can use the bind method in the gridview, detailsview, or formview control template, 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, bind functions must be used in edititemtemplate or insertitemtemplate of the data binding control.
The bind method is usually used with the input control, for example, the Textbox Control rendered by the row of the gridview in editing mode. When the data binding control creates these input controls as a part of its own rendering, this method can extract the input value.
The bind method uses the name of the data field as the parameter to associate with the bound property.