【正文】
cations are secure. Data Binding Overview and Syntax introduces a new declarative data binding syntax. This extremely flexible syntax permits the developer to bind not only to data sources, but also to simple properties, collections, expressions, and even results returned from method calls. The following table shows some examples of the new syntax. Although this syntax looks similar to the ASP shortcut for %= % its behavior is quite different. Whereas the ASP shortcut syntax was evaluated when the page was processed, the data binding syntax is evaluated only when the DataBind method is invoked. DataBind is a method of the Page and all server controls. When you call DataBind on a parent control, it cascades to all of the children of the control. So, for example, () invokes the DataBind method on each of the controls in the DataList templates. Calling DataBind on the Page () or simply DataBind() causes all data binding expressions on the page to be evaluated. DataBind is monly called from the Page_Load event, as shown in the following example. You can use a binding expression almost anywhere in the declarative section of an .aspx page, provided it evaluates to the expected data type at run time. The simple property, expression, and method examples above display text to the user when evaluated. In these cases, the data binding expression must evaluate to a value of type String. In the collection example, the data binding expression evaluates to a value of valid type for the DataSource property of ListBox. You might find it necessary to coerce the type of value in your binding expression to produce the desired result. For example, if count is an integer: Number of Records: % () % Binding to Simple Properties The data binding syntax supports binding to public variables, properties of the Page, and properties of other controls on the page. The following example illustrates binding to a public variable and simple property on the page. Note that these values are initialized before DataBind() is called. The following example illustrates binding to a property of another control. Binding to Collections and Lists List server controls like DataGrid, ListBox and HTMLSelect use a collection as a data source. The following examples illustrate binding to usual mon language runtime collection types. These controls can bind only to collections that support the IEnumerable, ICollection, or IListSource interface. Most monly, you39。ll bind to ArrayList, Hashtable, DataView and DataReader. The following example illustrates binding to an ArrayList. The following example illustrates binding to a DataView. Note that the DataView class