TemplateContainerAttribute.BindingDirection 屬性

定義

取得容器控制項的繫結方向。

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

屬性值

BindingDirection

BindingDirection,表示容器控制項的繫結方向。 預設為 OneWay

範例

下列程式碼範例示範如何建立名為 的 TemplatedFirstControl 樣板化控制項,並將它與名為 的 FirstTemplateContainer 容器產生關聯。 這可讓您建立自訂控制項,以在未指定範本時顯示伺服器時間,以及在指定範本時顯示範本的內容。 方法 GetCustomAttributeBindingDirection 決定 之 屬性的 TemplateFirstControl 屬性 FirstTemplate

此程式碼範例是提供給 類別之較大範例的 TemplateContainerAttribute 一部分。

// 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

備註

屬性 BindingDirection 可以是 OneWay 欄位,其中範本只能接受屬性值或 TwoWay 欄位,而範本可以接受並公開屬性值。 在後者的案例中,資料繫結控制項會自動使用 Bind 資料系結語法來更新、刪除和插入資料來源的作業。

如需資料系結的詳細資訊,請參閱 系結至資料庫 和資料 系結運算式概觀

適用於

另請參閱