DataBinding 클래스

정의

ASP.NET 서버 컨트롤의 단일 데이터 바인딩 식에 대한 정보를 포함하여 Microsoft Visual Studio와 같은 RAD(신속한 애플리케이션 개발) 디자이너가 디자인 타임에 데이터 바인딩 식을 만들 수 있도록 합니다. 이 클래스는 상속될 수 없습니다.

public ref class DataBinding sealed
public sealed class DataBinding
type DataBinding = class
Public NotInheritable Class DataBinding
상속
DataBinding

예제

다음 코드 예제에서는 DataBinding 개체 및 컨트롤의 기존 개체 같음 집합 DataBindingCollection 포함 된 컬렉션을 propertyName 매개 변수 값을 사용 하 여 Text입니다. 컬렉션에 포함 하는 경우는 DataBinding 개체를 propertyName 의 값 Text,이 코드는 개체의 값을 반환 합니다. Expression 속성. 이러한 개체가 없으면 빈 문자열 반환 합니다 ("").

// Create the custom class that accesses the DataBinding and
// DataBindingCollection classes at design time.
public class SimpleDesigner : System.Web.UI.Design.ControlDesigner
{
    // 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");
        }
    }
    protected void PropertyChanged(string propName)
    {
        IControlDesignerTag myHtmlControlDesignBehavior = this.Tag;
        
        DataBindingCollection myDataBindingCollection;
        DataBinding myDataBinding1, myDataBinding2;
        String myStringReplace1, myDataBindingExpression1, removedBinding, removedBindingAfterReplace, myDataBindingExpression2, myStringReplace2;
        string[] removedBindings1, removedBindings2;
        Int32 temp;

        if (myHtmlControlDesignBehavior == null)
            return;
        // Use the DataBindingCollection constructor to 
        // create the myDataBindingCollection1 object.
        // Then set this object equal to the
        // DataBindings property of the control created
        // by this custom designer.
        DataBindingCollection myDataBindingCollection1 = new DataBindingCollection();
        myDataBindingCollection1 = myDataBindingCollection = DataBindings;
        if (myDataBindingCollection.Contains(propName))
        {
            myDataBinding1 = myDataBindingCollection[propName];
            myStringReplace1 = propName.Replace(".", "-");
            if (myDataBinding1 == null)
            {
                myHtmlControlDesignBehavior.RemoveAttribute(myStringReplace1);
                return;
            }
            // DataBinding is not null.
            myDataBindingExpression1 = String.Concat("<%#", myDataBinding1.Expression, "%>");
            myHtmlControlDesignBehavior.SetAttribute(myStringReplace1, myDataBindingExpression1);
            int index = myStringReplace1.IndexOf("-");
        }
        else
        {
            // Use the DataBindingCollection.RemovedBindings 
            // property to set the value of the removedBindings
            // arrays.
            removedBindings2 = removedBindings1 = DataBindings.RemovedBindings;
            temp = 0;
            while (removedBindings2.Length > temp)
            {
                removedBinding = removedBindings2[temp];
                removedBindingAfterReplace = removedBinding.Replace('.', '-');
                myHtmlControlDesignBehavior.RemoveAttribute(removedBindingAfterReplace);
                temp = temp + 1;
            }
        }
        // Use the DataBindingCollection.GetEnumerator method
        // to iterate through the myDataBindingCollection object
        // and write the PropertyName, PropertyType, and Expression
        // properties to a file for each DataBinding object
        // in the MyDataBindingCollection object. 
        myDataBindingCollection = DataBindings;
        IEnumerator myEnumerator = myDataBindingCollection.GetEnumerator();

        while (myEnumerator.MoveNext())
        {
            myDataBinding2 = (DataBinding)myEnumerator.Current;
            String dataBindingOutput1, dataBindingOutput2, dataBindingOutput3;
            dataBindingOutput1 = String.Concat("The property name is ", myDataBinding2.PropertyName);
            dataBindingOutput2 = String.Concat("The property type is ", myDataBinding2.PropertyType.ToString(), "-", dataBindingOutput1);
            dataBindingOutput3 = String.Concat("The expression is ", myDataBinding2.Expression, "-", dataBindingOutput2);
            WriteToFile(dataBindingOutput3);

            myDataBindingExpression2 = String.Concat("<%#", myDataBinding2.Expression, "%>");
            myStringReplace2 = myDataBinding2.PropertyName.Replace(".", "-");
            myHtmlControlDesignBehavior.SetAttribute(myStringReplace2, myDataBindingExpression2);
            int index = myStringReplace2.IndexOf('-');
        }// while loop ends
    }
    public void WriteToFile(string input)
    {
        // The WriteToFile custom method writes
        // the values of the DataBinding properties
        // to a file on the C drive at design time.
        StreamWriter myFile = File.AppendText("C:\\DataBindingOutput.txt");
        ASCIIEncoding encoder = new ASCIIEncoding();
        byte[] ByteArray = encoder.GetBytes(input);
        char[] CharArray = encoder.GetChars(ByteArray);
        myFile.WriteLine(CharArray, 0, input.Length);
        myFile.Close();
    }
}
' Create the custom class that accesses the DataBinding and
' DataBindingCollection classes at design time.

Public Class SimpleDesigner
    Inherits System.Web.UI.Design.ControlDesigner
    ' 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

    Protected Sub PropertyChanged(ByVal propName As String)
        Dim myHtmlControlDesignBehavior As IControlDesignerTag = Me.Tag
        Dim myDataBindingCollection As DataBindingCollection
        Dim myDataBinding1, myDataBinding2 As DataBinding
        Dim myStringReplace1, myDataBindingExpression1, removedBinding, removedBindingAfterReplace, myDataBindingExpression2, myStringReplace2 As [String]
        Dim removedBindings1(), removedBindings2() As String
        Dim temp As Int32

        If myHtmlControlDesignBehavior Is Nothing Then
            Return
        End If

        myDataBindingCollection = DataBindings
        ' Use the DataBindingCollection constructor to 
        ' create the myDataBindingCollection1 object.
        ' Then set this object equal to the
        ' DataBindings property of the control created
        ' by this custom designer.
        Dim myDataBindingCollection1 As New DataBindingCollection()
        myDataBindingCollection1 = DataBindings
        myDataBindingCollection = DataBindings
        If (myDataBindingCollection.Contains(propName)) Then
            myDataBinding1 = myDataBindingCollection(propName)
            myStringReplace1 = propName.Replace(".", "-")
            If myDataBinding1 Is Nothing Then
                myHtmlControlDesignBehavior.RemoveAttribute(myStringReplace1)
                Return
            End If
            ' DataBinding is not null.
            myDataBindingExpression1 = [String].Concat("<%#", myDataBinding1.Expression, "%>")
            myHtmlControlDesignBehavior.SetAttribute(myStringReplace1, myDataBindingExpression1)
            Dim index As Integer = myStringReplace1.IndexOf("-")
        Else
            ' Use the DataBindingCollection.RemovedBindings 
            ' property to set the value of the removedBindings
            ' arrays.
            removedBindings1 = DataBindings.RemovedBindings
            removedBindings2 = DataBindings.RemovedBindings
            temp = 0
            While removedBindings2.Length > temp
                removedBinding = removedBindings2(temp)
                removedBindingAfterReplace = removedBinding.Replace("."c, "-"c)
                myHtmlControlDesignBehavior.RemoveAttribute(removedBindingAfterReplace)
                temp = temp & 1
            End While
        End If
        ' Use the DataBindingCollection.GetEnumerator method
        ' to iterate through the myDataBindingCollection object
        ' and write the PropertyName, PropertyType, and Expression
        ' properties to a file for each DataBinding object
        ' in the MyDataBindingCollection object. 
        myDataBindingCollection = DataBindings
        Dim myEnumerator As IEnumerator = myDataBindingCollection.GetEnumerator()

        While myEnumerator.MoveNext()
            myDataBinding2 = CType(myEnumerator.Current, DataBinding)
            Dim dataBindingOutput1, dataBindingOutput2, dataBindingOutput3 As [String]
            dataBindingOutput1 = [String].Concat("The property name is ", myDataBinding2.PropertyName)
            dataBindingOutput2 = [String].Concat("The property type is ", myDataBinding2.PropertyType.ToString(), "-", dataBindingOutput1)
            dataBindingOutput3 = [String].Concat("The expression is ", myDataBinding2.Expression, "-", dataBindingOutput2)
            WriteToFile(dataBindingOutput3)

            myDataBindingExpression2 = [String].Concat("<%#", myDataBinding2.Expression, "%>")
            myStringReplace2 = myDataBinding2.PropertyName.Replace(".", "-")
            myHtmlControlDesignBehavior.SetAttribute(myStringReplace2, myDataBindingExpression2)
            Dim index As Integer = myStringReplace2.IndexOf("-"c)
        End While ' while loop ends
    End Sub
    Public Sub WriteToFile(ByVal input As String)
        ' The WriteToFile custom method writes
        ' the values of the DataBinding properties
        ' to a file on the C drive at design time.
        Dim myFile As StreamWriter = File.AppendText("C:\DataBindingOutput.txt")
        Dim encoder As New ASCIIEncoding()
        Dim ByteArray As Byte() = encoder.GetBytes(input)
        Dim CharArray As Char() = encoder.GetChars(ByteArray)
        myFile.WriteLine(CharArray, 0, input.Length)
        myFile.Close()
    End Sub
End Class

설명

인스턴스에서 서버 컨트롤의 각 데이터 바인딩 식을 디자인 타임에 표시 됩니다는 DataBinding 클래스입니다. 하나 이상의 데이터 바인딩 식을 포함 하는 모든 서버 컨트롤에는 DataBindingCollection 포함 된 개체는 DataBinding 개체입니다. 이 컬렉션은는 Control 구현 하는 클래스는 IDataBindingsAccessor 인터페이스입니다. 사용자 지정 RAD 디자이너를 만들면 구현을 사용 하 여 해당 컬렉션에 액세스 합니다. 모든 DataBinding 또는 DataBindingCollection 서버 컨트롤과 연결 된 개체는 디자인 타임에만 존재 합니다. 런타임 시 존재 하지 않는 하며, 따라서 액세스할 수 없는 런타임 중입니다.

생성자

DataBinding(String, Type, String)

DataBinding 클래스의 새 인스턴스를 초기화합니다.

속성

Expression

계산될 데이터 바인딩 식을 가져오거나 설정합니다.

PropertyName

데이터 바인딩될 ASP.NET 서버 컨트롤 속성의 이름을 가져옵니다.

PropertyType

데이터 바인딩된 ASP.NET 서버 컨트롤 속성의 .NET Framework 형식을 가져옵니다.

메서드

Equals(Object)

지정된 개체가 현재 개체와 같은 DataBinding 클래스의 인스턴스인지 여부를 결정합니다.

GetHashCode()

DataBinding 개체의 인스턴스에 대한 해시 코드를 가져옵니다.

GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

적용 대상

추가 정보