TemplateContainerAttribute.BindingDirection Egenskap

Definition

Hämtar bindningsriktningen för containerkontrollen.

public:
 property System::ComponentModel::BindingDirection BindingDirection { System::ComponentModel::BindingDirection get(); };
public System.ComponentModel.BindingDirection BindingDirection { get; }
member this.BindingDirection : System.ComponentModel.BindingDirection
Public ReadOnly Property BindingDirection As BindingDirection

Egenskapsvärde

En BindingDirection som anger containerkontrollens bindningsriktning. Standardvärdet är OneWay.

Exempel

I följande kodexempel visas hur du skapar en mallkontroll med namnet TemplatedFirstControl och associerar den med en container med namnet FirstTemplateContainer. På så sätt kan du skapa anpassade kontroller som visar servertiden när mallen inte har angetts och innehållet i mallen när mallen har angetts. Metoden GetCustomAttribute bestämmer BindingDirection egenskapen för FirstTemplate egenskapen för TemplateFirstControl.

Det här kodexemplet är en del av ett större exempel för TemplateContainerAttribute klassen.

// Get the class type for which to access metadata.
Type clsType = typeof(TemplatedFirstControl);
// Get the PropertyInfo object for FirstTemplate.
PropertyInfo pInfo = clsType.GetProperty("FirstTemplate");
// See if the TemplateContainer attribute is defined for this property.
bool isDef = Attribute.IsDefined(pInfo, typeof(TemplateContainerAttribute));
// Display the result if the attribute exists.
if (isDef)
{
  TemplateContainerAttribute tca =
    (TemplateContainerAttribute)Attribute.GetCustomAttribute(pInfo, typeof(TemplateContainerAttribute));
  Response.Write("The binding direction is: " + tca.BindingDirection.ToString());
}
' Get the class type for which to access metadata.
Dim clsType As Type = GetType(VB_TemplatedFirstControl)
' Get the PropertyInfo object for FirstTemplate.
Dim pInfo As PropertyInfo = clsType.GetProperty("FirstTemplate")
' See if the TemplateContainer attribute is defined for this property.
Dim isDef As Boolean = Attribute.IsDefined(pInfo, GetType(TemplateContainerAttribute))
' Display the result if the attribute exists.
If isDef Then
  Dim tca As TemplateContainerAttribute = CType(Attribute.GetCustomAttribute(pInfo, GetType(TemplateContainerAttribute)), TemplateContainerAttribute)
  Response.Write("The binding direction is: " & tca.BindingDirection.ToString())
End If

Kommentarer

Egenskapen BindingDirection kan vara antingen fältet OneWay , där mallen endast kan acceptera egenskapsvärden eller TwoWay fältet, där mallen kan acceptera och exponera egenskapsvärden. I det senare scenariot kan databundna kontroller automatiskt använda uppdaterings-, borttagnings- och infogningsåtgärder för en datakälla med hjälp Bind av databindningssyntaxen.

Mer information om databindning finns i Bindning till databaser och översikt överData-Binding uttryck.

Gäller för

Se även