Share via


ListControlDataBindingHandler Classe

Définition

Effectue une liaison de données d'un contrôle serveur Web ListControl au sein d'un concepteur visuel.

public ref class ListControlDataBindingHandler : System::Web::UI::Design::DataBindingHandler
public class ListControlDataBindingHandler : System.Web.UI.Design.DataBindingHandler
type ListControlDataBindingHandler = class
    inherit DataBindingHandler
Public Class ListControlDataBindingHandler
Inherits DataBindingHandler
Héritage
ListControlDataBindingHandler

Exemples

Cette section contient deux exemples de code. La première montre comment dériver un contrôle du RadioButtonList contrôle et l’associer à son gestionnaire de liaison de données. La deuxième montre comment dériver une classe de la ListControlDataBindingHandler classe.

L’exemple de code suivant montre comment dériver le SimpleRadioButtonList contrôle du RadioButtonList contrôle, puis appliquer l’attribut pour associer le SimpleRadioButtonList DataBindingHandlerAttribute contrôle à son gestionnaire de liaison de données, la SimpleRadioButtonListDataBindingHandler classe.

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Security.Permissions;

namespace Examples.CS.WebControls.Design
{
    // The SimpleRadioButtonList is a copy of the RadioButtonList.
    // It uses the SimpleRadioButtonListDesigner for design-time support.
    [AspNetHostingPermission(SecurityAction.Demand, 
        Level = AspNetHostingPermissionLevel.Minimal)]
    [AspNetHostingPermission(SecurityAction.InheritanceDemand, 
        Level = AspNetHostingPermissionLevel.Minimal)]
    [Designer(typeof(Examples.CS.WebControls.Design.
       SimpleRadioButtonListDesigner))]
    [DataBindingHandler(typeof(Examples.CS.WebControls.Design.
        SimpleRadioButtonListDataBindingHandler))]
    public class SimpleRadioButtonList : RadioButtonList
    {
    } // SimpleRadioButtonList
} // Examples.CS.WebControls.Design
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.ComponentModel
Imports System.Security.Permissions

Namespace Examples.VB.WebControls.Design

    ' The SimpleRadioButtonList is a copy of the RadioButtonList.
    ' It uses the SimpleRadioButtonListDesigner for design-time support.
    <AspNetHostingPermission(SecurityAction.Demand, _
        Level:=AspNetHostingPermissionLevel.Minimal)> _
    <AspNetHostingPermission(SecurityAction.InheritanceDemand, _
        Level:=AspNetHostingPermissionLevel.Minimal)> _
    <DesignerAttribute(GetType(Examples.VB.WebControls.Design. _
        SimpleRadioButtonListDesigner))> _
    <DataBindingHandler(GetType(Examples.VB.WebControls.Design. _
        SimpleRadioButtonListDataBindingHandler))> _
    Public Class SimpleRadioButtonList
        Inherits RadioButtonList
    End Class
End Namespace ' Examples.VB.WebControls.Design

L’exemple de code suivant montre comment dériver la SimpleRadioButtonListDataBindingHandler classe de la ListControlDataBindingHandler classe. Elle remplace la DataBindControl méthode pour ajouter un message au contrôle associé SimpleRadioButtonList lorsque ce contrôle est lié aux données.

using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Web.UI;
using System.Web.UI.Design.WebControls;

namespace Examples.CS.WebControls.Design
{
    // Derive the SimpleRadioButtonListDataBindingHandler.
    public class SimpleRadioButtonListDataBindingHandler : 
        ListControlDataBindingHandler
    {
        // Override the DataBindControl. 
        public override void DataBindControl(IDesignerHost designerHost, 
            Control control)
        {
            // Create a reference, named dataSourceBinding, 
            // to the control DataSource binding.
            DataBinding dataSourceBinding = 
                ((IDataBindingsAccessor)control).DataBindings["DataSource"];

            // If the binding exists, create a reference to the
            // list control, clear its ListItemCollection, and then add
            // an item to the collection.
            if (! (dataSourceBinding == null))
            {
                SimpleRadioButtonList simpleControl = 
                    (SimpleRadioButtonList)control;

                simpleControl.Items.Clear();
                simpleControl.Items.Add("Data-bound Radio Button.");
            }
        } // DataBindControl
    } // SimpleRadioButtonListDataBindingHandler
} // Examples.CS.WebControls.Design
' Imports System.Design
Imports System.ComponentModel
Imports System.ComponentModel.Design
Imports System.Web.UI
Imports System.Web.UI.Design.WebControls

Namespace Examples.VB.WebControls.Design

    ' Derive the SimpleRadioButtonListDataBindingHandler.
    Public Class SimpleRadioButtonListDataBindingHandler
        Inherits ListControlDataBindingHandler

        ' Override the DataBindControl.
        Public Overrides Sub DataBindControl( _
        ByVal designerHost As IDesignerHost, _
        ByVal control As Control)

            ' Create a reference, named dataSourceBinding,
            ' to the control's DataSource binding.
            Dim dataSourceBinding As DataBinding _
                = CType( _
                control, _
                IDataBindingsAccessor).DataBindings("DataSource")

            ' If the binding exists, create a reference to the
            ' list control, clear its ListItemCollection, and then add
            ' an item to the collection.
            If Not (dataSourceBinding Is Nothing) Then
                Dim simpleControl As SimpleRadioButtonList = _
                    CType(control, SimpleRadioButtonList)

                simpleControl.Items.Clear()
                simpleControl.Items.Add("Data-bound Radio Button.")
            End If
        End Sub
    End Class
End Namespace ' Examples.VB.WebControls.Design

Remarques

La ListControlDataBindingHandler classe effectue une liaison de données au moment du design d’un ListControl contrôle. La ListControlDataBindingHandler classe est référencée par l’utilisation ListControl de la DataBindingHandlerAttribute classe.

La DataBindControl méthode effectue la liaison de données au moment du design.

Constructeurs

ListControlDataBindingHandler()

Initialise une nouvelle instance de la classe ListControlDataBindingHandler.

Méthodes

DataBindControl(IDesignerHost, Control)

Effectue une liaison de données sur le contrôle spécifié.

Equals(Object)

Détermine si l'objet spécifié est égal à l'objet actuel.

(Hérité de Object)
GetHashCode()

Fait office de fonction de hachage par défaut.

(Hérité de Object)
GetType()

Obtient le Type de l'instance actuelle.

(Hérité de Object)
MemberwiseClone()

Crée une copie superficielle du Object actuel.

(Hérité de Object)
ToString()

Retourne une chaîne qui représente l'objet actuel.

(Hérité de Object)

S’applique à

Voir aussi