次の方法で共有


DataBinding コンストラクタ

DataBinding クラスの新しいインスタンスを初期化します。

名前空間: System.Web.UI
アセンブリ: System.Web (system.web.dll 内)

構文

'宣言
Public Sub New ( _
    propertyName As String, _
    propertyType As Type, _
    expression As String _
)
'使用
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
)
適用できません。

パラメータ

  • propertyName
    データの連結先のプロパティ。
  • propertyType
    データの連結先のプロパティの .NET Framework 型。
  • expression
    評価されるデータ連結式。

使用例

DataBinding オブジェクトを作成し、propertyName パラメータの値が Text である、コントロールの DataBindingCollection コレクションの既存のオブジェクトと同じようにこのオブジェクトを設定する例を次に示します。propertyName の値が TextDataBinding オブジェクトがコレクションに含まれている場合、このコードは、オブジェクトの Expression プロパティの値を返します。そのようなオブジェクトがない場合は、空の文字列 ("") が返されます。

' 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

プラットフォーム

Windows 98,Windows Server 2000 SP4,Windows CE,Windows Millennium Edition,Windows Mobile for Pocket PC,Windows Mobile for Smartphone,Windows Server 2003,Windows XP Media Center Edition,Windows XP Professional x64 Edition,Windows XP SP2,Windows XP Starter Edition

Microsoft .NET Framework 3.0 は Windows Vista,Microsoft Windows XP SP2,および Windows Server 2003 SP1 でサポートされています。

バージョン情報

.NET Framework

サポート対象 : 3.0,2.0,1.1,1.0

参照

関連項目

DataBinding クラス
DataBinding メンバ
System.Web.UI 名前空間
DataBinder