Cet article a fait l'objet d'une traduction manuelle. Déplacez votre pointeur sur les phrases de l'article pour voir la version originale de ce texte. |
Traduction
Source
|
Control.DataBinding, événement
Se produit lorsque le contrôle serveur se lie à une source de données.
Assembly : System.Web (dans System.Web.dll)
/* Create a class that implements the ITemplate interface. This class overrides the InstantiateIn method to always place templates in a Literal object. It also creates a custom BindData method that is used as the event handler associated with the Literal object's DataBinding event. */ using System; using System.Web; using System.Data; using System.Web.UI; using System.Web.UI.WebControls; namespace UsingItemTemplates { public class GenericItem : ITemplate { private string column; public GenericItem(string column) { this.column = column; } // Override the ITemplate.InstantiateIn method to ensure // that the templates are created in a Literal control and // that the Literal object's DataBinding event is associated // with the BindData method. public void InstantiateIn(Control container) { Literal l = new Literal(); l.DataBinding += new EventHandler(this.BindData); container.Controls.Add(l); } // Create a public method that will handle the // DataBinding event called in the InstantiateIn method. public void BindData(object sender, EventArgs e) { Literal l = (Literal) sender; DataGridItem container = (DataGridItem) l.NamingContainer; l.Text = ((DataRowView) container.DataItem)[column].ToString(); } } }
Windows 7, Windows Vista SP1 ou ultérieur, Windows XP SP3, Windows XP SP2 Édition x64, Windows Server 2008 (installation minimale non prise en charge), Windows Server 2008 R2 (installation minimale prise en charge avec SP1 ou version ultérieure), Windows Server 2003 SP2
Le .NET Framework ne prend pas en charge toutes les versions de chaque plateforme. Pour obtenir la liste des versions prises en charge, consultez Configuration requise du .NET Framework.