This documentation is archived and is not being maintained.

DataBindingCollection.Item Property

Gets the DataBinding object with the specified property name.

[C#] In C#, this property is the indexer for the DataBindingCollection class.

[Visual Basic]
Public Default ReadOnly Property Item( _
   ByVal propertyName As String _
) As DataBinding
[C#]
public DataBinding this[
 string propertyName
] {get;}
[C++]
public: __property DataBinding* get_Item(
 String* propertyName
);
[JScript]
returnValue = DataBindingCollectionObject.Item(propertyName);
-or-
returnValue = DataBindingCollectionObject(propertyName);

[JScript] In JScript, you can use the default indexed properties defined by a type, but you cannot explicitly define your own. However, specifying the expando attribute on a class automatically provides a default indexed property whose type is Object and whose index type is String.

Arguments [JScript]

propertyName
The name of the property to be found.

Parameters [Visual Basic, C#, C++]

propertyName
The name of the property to be found.

Property Value

The DataBinding object with the specified property name. If no object with the specified name exists, this value is a null reference (Nothing in Visual Basic).

Example

[Visual Basic, C#, C++] The following example creates a new DataBinding object using the Item property to associate the new object with an existing object in the collection whose DataBinding.PropertyName property value is Text.

[Visual Basic] 
' 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
      
      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
      OnBindingsCollectionChanged("Text")
   End Set
End Property


[C#] 
// 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);
       }
       OnBindingsCollectionChanged("Text");
    }
 }

[C++] 
// 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 String* get_Text() {
   DataBinding* myBinding = DataBindings->Item[S"Text"];
   if (myBinding != 0) {
      return myBinding->Expression;
   }
   return String::Empty;
}
__property void set_Text(String* value) {

   if ((value == 0) || (value->Length == 0)) {
      DataBindings->Remove(S"Text");
   } else {

      DataBinding* binding = DataBindings->Item[S"Text"];

      if (binding == 0) {
         binding = new DataBinding(S"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=dynamic_cast<DataBinding*>(DataBindings->SyncRoot);
      DataBindings->Add(binding);
      DataBindings->Add(binding1);
   }
   OnBindingsCollectionChanged(S"Text");
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family

See Also

DataBindingCollection Class | DataBindingCollection Members | System.Web.UI Namespace

Show: