Cet article a fait l’objet d’une traduction automatique. Pour afficher l’article en anglais, activez la case d’option Anglais. Vous pouvez également afficher le texte anglais dans une fenêtre contextuelle en faisant glisser le pointeur de la souris sur le texte traduit.
Traduction
Anglais

Control.DataBind méthode ()

 

Date de publication : novembre 2016

Lie une source de données au contrôle serveur appelé et à tous ses contrôles enfants.

Espace de noms:   System.Web.UI
Assembly:  System.Web (dans System.Web.dll)

public virtual void DataBind()

Use this method to bind data from a source to a server control. This method is commonly used after retrieving a dataset through a database query. Most controls perform data binding automatically, which means that you typically do not need to call this method explicitly.

This method is commonly overridden when you create a custom templated data-bound control. For more information, see How to: Create Templated User Controls and Developing Custom Data-Bound Web Server Controls. When called on a server control, this method resolves all data-binding expressions in the server control and in any of its child controls.

The following example overrides the M:System.Web.UI.Control.DataBind method in a custom ASP.NET server control. It begins by calling the base M:System.Web.UI.Control.OnDataBinding(System.EventArgs) method and then uses the M:System.Web.UI.ControlCollection.Clear method to delete all the child controls and the M:System.Web.UI.Control.ClearChildViewState method to delete any saved view-state settings for those child controls. Finally, the P:System.Web.UI.Control.ChildControlsCreated property is set to true and the control is instructed to track any changes to the view state of the newly created controls with the M:System.Web.UI.Control.TrackViewState method. This is a common technique when binding data to a control to ensure that new data does not conflict with data stored from a previous M:System.Web.UI.Control.DataBind method call.

public override void DataBind() 
{
   base.OnDataBinding(EventArgs.Empty);
   // Reset the control's state.
   Controls.Clear();
   // Check for HasChildViewState to avoid unnecessary calls to ClearChildViewState.
   if (HasChildViewState)
      ClearChildViewState();
   ChildControlsCreated = true;
   if (!IsTrackingViewState)
      TrackViewState();
}

.NET Framework
Disponible depuis 1.1
Retour au début
Afficher: