Riferimento a .NET Framework
Evento Control.DataBinding
Il presente articolo è stato tradotto manualmente. Per visualizzare questa pagina e contemporaneamente visualizzarne il contenuto in lingua inglese, passare alla visualizzazione semplificata.
Viene generato quando il controllo server viene associato a un'origine dati.
Assembly: System.Web (in System.Web.dll)
Sintassi
Visual Basic
Public Event DataBinding As EventHandler
C#
public event EventHandler DataBinding
Visual C++
public: event EventHandler^ DataBinding { void add (EventHandler^ value); void remove (EventHandler^ value); }
F#
member DataBinding : IEvent<EventHandler,
EventArgs>
Note
Questo evento notifica al controllo server l'esecuzione di qualsiasi funzione logica di associazione dati scritta per il controllo.
Esempi
Visual Basic
' 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. Imports System Imports System.Web Imports System.Data Imports System.Web.UI Imports System.Web.UI.WebControls Namespace UsingItemTemplatesVB Public Class GenericItem Implements ITemplate Private column As String Public Sub New(column As String) Me.column = column End Sub 'New ' 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 Sub InstantiateIn(container As Control) Implements ITemplate.InstantiateIn Dim l As New Literal() AddHandler l.DataBinding, AddressOf Me.BindData container.Controls.Add(l) End Sub 'InstantiateIn ' Create a public method that will handle the ' DataBinding event called in the InstantiateIn method. Public Sub BindData(sender As Object, e As EventArgs) Dim l As Literal = CType(sender, Literal) Dim container As DataGridItem = CType(l.NamingContainer, DataGridItem) l.Text = CType(container.DataItem, DataRowView)(column).ToString() End Sub 'BindData End Class 'GenericItem End Namespace 'UsingItemTemplatesVB
C#
/* 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(); } } }
Informazioni sulla versione
.NET Framework
Supportato in: 4, 3.5, 3.0, 2.0, 1.1, 1.0Piattaforme
Windows 7, Windows Vista SP1 o versione successiva, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (componenti di base del server non supportati), Windows Server 2008 R2 (componenti di base del server supportati con SP1 o versione successiva), Windows Server 2003 SP2
.NET Framework non supporta tutte le versioni di ciascuna piattaforma. Per un elenco delle versioni supportate, vedere Requisiti di sistema di .NET Framework.
Vedere anche