Data Binding Server Control
Data Binding Overview and Syntax ASP.NET introduces a new declarative data binding syntax. This very flexible syntax allows developers to not only bind to data sources, but also bind to simple properties, collections, expressions or even results returned from methods. The following table shows some examples of new grammar. Simple Attributes Customer: <% # custom%> Collection Orders: Expression Contact: <% # (Customer.First Name " Customer.lastname)%> Method Outstanding Balance: <% # getBalance (CustID)%> Although this syntax looks similar to the ASP's response.write shortcut <% =%>, its behavior is completely different. ASP Response.write Shortcut Syntax Calculates when the page is processed, and the ASP.NET data binding syntax is calculated only when the DataBind method is called. Database is a way pages and all server controls. When you call DataBind on the parent control, it cascades all child controls for the control. For example, DataList1.DATABIND () will then call the DataBind method for each control in the DataList template. Call data on page on the page () or just databind () - will cause all data binding expressions on the calculation page. Database from the Page_Load event is usually called, as shown in the following example. protected void Page_Load (Object Src, EventArgs E) {DataBind ();} Protected Sub Page_Load (Src As Object, E As EventArgs) DataBind () End Subprotected function Page_Load (Src: Object, E: EventArgs): void {DataBind () } If the binding expression is calculated as the expected data type at runtime, you can use a binding expression in almost anywhere in the .aspx page declaration section. The above simple properties, expressions, and method examples displays text to the user when calculating. In these cases, the data binding expression must be calculated as the value of the String type. In a collection example, the data binding expression calculates the valid type value of the DataSource attribute of ListBox. You may find that it is necessary to convert the type value in the binding expression to generate the desired result. For example, if count is an integer: Number of Records: <% # Count.tostring ()%> Bind to simple properties ASP.NET data binding syntax supports the properties of the public variables, page properties, and other controls . The following example shows how to bind to the simple properties of the public variables and pages. Note that these values initialize before the data call () call.