Freigeben über


DataBinding-Konstruktor

Initialisiert eine neue Instanz der DataBinding-Klasse.

Namespace: System.Web.UI
Assembly: System.Web (in system.web.dll)

Syntax

'Declaration
Public Sub New ( _
    propertyName As String, _
    propertyType As Type, _
    expression As String _
)
'Usage
Dim propertyName As String
Dim propertyType As Type
Dim expression As String

Dim instance As New DataBinding(propertyName, propertyType, expression)
public DataBinding (
    string propertyName,
    Type propertyType,
    string expression
)
public:
DataBinding (
    String^ propertyName, 
    Type^ propertyType, 
    String^ expression
)
public DataBinding (
    String propertyName, 
    Type propertyType, 
    String expression
)
public function DataBinding (
    propertyName : String, 
    propertyType : Type, 
    expression : String
)

Parameter

  • propertyName
    Die Eigenschaft, an die Daten gebunden werden sollen.
  • propertyType
    Der .NET Framework-Typ der Eigenschaft, an die Daten gebunden werden soll.
  • expression
    Der Datenbindungsausdruck, der ausgewertet werden soll.

Beispiel

Im folgenden Codebeispiel wird ein DataBinding-Objekt erstellt, und dieses wird gleichgesetzt mit einem vorhandenen Objekt in der DataBindingCollection-Auflistung des Steuerelements, das über einen propertyName-Parameter mit dem Wert Text verfügt. Wenn die Auflistung ein DataBinding-Objekt mit einem propertyName-Wert von Text enthält, gibt dieser Code den Wert der Expression-Eigenschaft des Objekts zurück. Wenn kein solches Objekt vorhanden ist, wird eine leere Zeichenfolge ("") zurückgegeben.

' 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
// 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.
/** @property 
 */
public String get_Text()
{
    DataBinding myBinding = get_DataBindings().get_Item("Text");
    if (myBinding != null) {
        return myBinding.get_Expression();
    }
    return("");
} //get_Text

/** @property 
 */
public void set_Text(String value)
{
    if (value == null || value.get_Length() == 0) {
        get_DataBindings().Remove("Text");
    }
    else {
        DataBinding binding = get_DataBindings().get_Item("Text");
        if (binding == null) {
            binding = new DataBinding("Text", String.class.ToType(), value);
        }
        else {
            binding.set_Expression(value);
        }

        // Call the DataBinding constructor, then add
        // the initialized DataBinding object to the 
        // DataBindingCollection for this custom designer.
        DataBinding binding1 = (DataBinding)(get_DataBindings().
            get_SyncRoot());
        get_DataBindings().Add(binding);
        get_DataBindings().Add(binding1);
    }
    OnBindingsCollectionChanged("Text");
} //set_Text

Plattformen

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

Siehe auch

Referenz

DataBinding-Klasse
DataBinding-Member
System.Web.UI-Namespace
DataBinder-Klasse