Name
DataBind
Synopsis
Page.DataBind( )
Evaluates and resolves any data binding expressions in the page. It also calls DataBind on all child controls.
Parameters
None
Example
The following code example uses a data binding expression to set the
ForeColor
attribute of a label control tag to the
value of local variable named color. When the DataBind method is
called in Page_Load, the value of the Color variable is assigned to
the ForeColor
attribute (which is effectively the
same as setting the ForeColor property in code):
<%@ Page Language="vb" %> <html> <head> <title></title> <script runat="server"> Dim Color As System.Drawing.Color = System.Drawing.Color.Red Sub Page_Load( ) Message.Text = "ForeColor is: " & Color.Name DataBind( ) End Sub </script> </head> <body> <asp:label id="Message" ForeColor="<%# Color %>" runat="server"/> </body> </html>
Notes
If you want to perform data binding on a specific control on the page, such as a DataGrid or DataList control, it may be more efficient to call DataBind on that control rather than on the page, since calling it on the control will avoid any overhead in calling DataBind on controls for which data binding is not needed.
Get ASP.NET in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.