Compartir a través de


DataBinding(String, Type, String) Constructor

Definición

Inicializa una nueva instancia de la clase DataBinding.

public:
 DataBinding(System::String ^ propertyName, Type ^ propertyType, System::String ^ expression);
public DataBinding (string propertyName, Type propertyType, string expression);
new System.Web.UI.DataBinding : string * Type * string -> System.Web.UI.DataBinding
Public Sub New (propertyName As String, propertyType As Type, expression As String)

Parámetros

propertyName
String

Propiedad a la que enlazar datos.

propertyType
Type

Tipo .NET Framework de la propiedad a la que se van a enlazar datos.

expression
String

Expresión de enlace a datos que se va a evaluar.

Ejemplos

En el ejemplo de código siguiente se crea un DataBinding objeto y se establece igual a un objeto existente en la colección del DataBindingCollection control que tiene un propertyName parámetro con un valor de Text. Si la colección contiene un DataBinding objeto con un propertyName valor de Text, este código devuelve el valor de la propiedad del Expression objeto. Si no hay ningún objeto de este tipo, devuelve una cadena vacía ("").

// Create a Text property with accessors that obtain 
// the property value from and set the property value
// to the Text key in the DataBindingCollection class.
public string Text
{
    get
    {
        DataBinding myBinding = DataBindings["Text"];
        if (myBinding != null)
        {
            return myBinding.Expression;
        }
        return String.Empty;
    }
    set
    {

        if ((value == null) || (value.Length == 0))
        {
            DataBindings.Remove("Text");
        }
        else
        {

            DataBinding binding = DataBindings["Text"];

            if (binding == null)
            {
                binding = new DataBinding("Text", typeof(string), value);
            }
            else
            {
                binding.Expression = value;
            }
            // Call the DataBinding constructor, then add
            // the initialized DataBinding object to the 
            // DataBindingCollection for this custom designer.
            DataBinding binding1 = (DataBinding)DataBindings.SyncRoot;
            DataBindings.Add(binding);
            DataBindings.Add(binding1);
        }
        PropertyChanged("Text");
    }
}
' Create a Text property with accessors that obtain 
' the property value from and set the property value
' to the Text key in the DataBindingCollection class.

Public Property [Text]() As String
    Get
        Dim myBinding As DataBinding = DataBindings("Text")
        If Not (myBinding Is Nothing) Then
            Return myBinding.Expression
        End If
        Return String.Empty
    End Get
    Set(ByVal value As String)

        If value Is Nothing OrElse value.Length = 0 Then
            DataBindings.Remove("Text")
        Else

            Dim binding As DataBinding = DataBindings("Text")

            If binding Is Nothing Then
                binding = New DataBinding("Text", GetType(String), value)
            Else
                binding.Expression = value
            End If
            ' Call the DataBinding constructor, then add
            ' the initialized DataBinding object to the 
            ' DataBindingCollection for this custom designer.
            Dim binding1 As DataBinding = CType(DataBindings.SyncRoot, DataBinding)
            DataBindings.Add(binding)
            DataBindings.Add(binding1)
        End If
        PropertyChanged("Text")
    End Set
End Property

Se aplica a

Consulte también