ASP 2.0 data binding function EVAL () mechanism

xiaoxiao2021-03-31  219

Author: walkdan

This article assumes that you have learned the mechanism of the data binding of the ASP 1.1 (especially the local variable of Container), which mainly analyzes ASP 2.0 data binding to do those improvements.

ASP.NET 2.0 data binding function EVAL () simplifies ASP 1.1 mysterious Container.DataItem, such as data binding expressions:

<% # (Container.DataItem As DataRowView) ["ProductName"]. TOSTRING ()%>

The ASP 1.1 is simplified to: (remove the type specified, EVAL is realized by reflection, this article is no longer elaborated) <% # databinder.eval (container.DataItem, "productname"). Tostring ()%>

ASP 2.0 is simplified to remove the Container local variable: <% # eval ("ProductName")%> So, how is "ProductName" is the properties of that data, that is, Container.DataItem really Have you lost? Eval () is the method of parent class TemplateControl. TemplateControl.eval () can automatically calculate the Container, the mechanism is obtained from a DataBinding Convertext: Stack Stack. 1. Establish a DataItem Container Stack: In Control.Database (), create, so that the DataItem Container of the child control is always on the top of the stack. public class Control {protected virtual void DataBind (bool raiseOnDataBinding) {bool foundDataItem = false; if (this.IsBindingContainer) {object o = DataBinder.GetDataItem (this, out foundDataItem); if (foundDataItem) Page.PushDataItemContext (o); < - Press DataItem into the stack} Try {if (raiseondatabase) ONDATABINDING (Eventargs.empty); dataBindChildren (); <- binding subcontrol} Finally {if (FoundDataItem) Page.PopdataItemContext (); <- Put DataItem Pop-up stack}}}}

转载请注明原文地址:https://www.9cbs.com/read-131020.html

New Post(0)