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
Ce sujet n'a pas encore été évalué - Évaluez ce sujet

Control.DataBinding, événement

Se produit lorsque le contrôle serveur se lie à une source de données.

Espace de noms :  System.Web.UI
Assembly :  System.Web (dans System.Web.dll)
public event EventHandler DataBinding

Cet événement avertit le contrôle serveur qu'il doit exécuter une logique de liaison de données qui a été écrite à son intention.


/* 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();

        }
    }
}


.NET Framework

Pris en charge dans : 4, 3.5, 3.0, 2.0, 1.1, 1.0

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.
Cela vous a-t-il été utile ?
(1500 caractères restants)
Contenu de la communauté Ajouter
Annotations FAQ