DataBinder 클래스

정의

데이터 바인딩 식 구문을 생성하고 구문 분석하는 RAD(신속한 애플리케이션 개발) 디자이너를 지원합니다. 이 클래스는 상속할 수 없습니다.

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

예제

다음 예제에서는 정적 GetPropertyValue 메서드를 사용 하 여 개체를 사용 하 여 RepeaterArrayList 컨트롤의 Product 필드를 채웁다. 메서드는 Eval 동일한 구문을 사용하여 적용할 수 있지만 빠르게 수행되지는 않습니다.

이 예제에서는 문자열 Product 속성과 숫자 Model 속성을 노출하는 사용자 지정 UnitPrice 클래스를 사용합니다.

<%@ Page Language="C#" %>
<%@ Import Namespace="ASPSample" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void  Page_Load(object sender, EventArgs e)
{
        // Create and populate an ArrayList to store the products.
        ArrayList ProductList = new ArrayList();
        ProductList.Add(new Product("Standard", 99.95));
        ProductList.Add(new Product("Deluxe", 159.95));

        // Bind the array list to Repeater
        ListRepeater.DataSource = ProductList;
        ListRepeater.DataBind();
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>DataBinder Example</title>
</head>
<body>
<form id="Form2" runat="server">
<table>
<asp:Repeater id="ListRepeater" runat="server">
    <HeaderTemplate>
    <tr>
        <th style="width:50; text-align:left">Model</th>
        <th style="width:100; text-align:right">Unit Price</th>
    </tr>
    </HeaderTemplate>
    <ItemTemplate>
    <tr>
        <!-- Databind to the Product information using the DataBinder methods. 
             The Container.DataItem refers to the ArrayList object bound to 
             the ASP:Repeater in the Page Load event. -->
        <td>
            <%#DataBinder.GetPropertyValue(Container.DataItem, "Model")%>
        </td>
        <!-- Format the UnitPrice as currency. ({0:c}) -->
        <td style="text-align:right">
            <%#DataBinder.GetPropertyValue(Container.DataItem,
                         "UnitPrice", "{0:c}")%>
        </td>
    </tr>
    </ItemTemplate>
</asp:Repeater>
</table>
</form>
</body>
</html>
<%@ Page Language="vb" %>
<%@ Import Namespace="ASPSample" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
    Private Sub Page_Load(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles MyBase.Load

        ' Create and populate an ArrayList to store the products.
        Dim ProductList As New ArrayList
        ProductList.Add(New Product("Standard", 99.95))
        ProductList.Add(New Product("Deluxe", 159.95))

        ' Bind the array list to Repeater
        ListRepeater.DataSource = ProductList
        ListRepeater.DataBind()

    End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>DataBinder Example</title>
</head>
<body>
<form id="Form2" runat="server">
<table>
<asp:Repeater id="ListRepeater" runat="server">
    <HeaderTemplate>
    <tr>
        <th style="width:50; text-align:left">Model</th>
        <th style="width:100; text-align:right">Unit Price</th>
    </tr>
    </HeaderTemplate>
    <ItemTemplate>
    <tr>
        <!-- Databind to the Product information using the DataBinder methods. 
             The Container.DataItem refers to the ArrayList object bound to 
             the ASP:Repeater in the Page Load event. -->
        <td>
            <%#DataBinder.GetPropertyValue(Container.DataItem, "Model")%>
        </td>
        <!-- Format the UnitPrice as currency. ({0:c}) -->
        <td style="text-align:right">
            <%#DataBinder.GetPropertyValue(Container.DataItem, _
                         "UnitPrice", "{0:c}")%>
        </td>
    </tr>
    </ItemTemplate>
</asp:Repeater>
</table>
</form>
</body>
</html>

다음 코드는 사용자 지정 Product 클래스입니다. 이 코드는 Product.cs 또는 Product.vb 같은 App_Code 디렉터리의 별도 클래스 파일에 포함되어야 합니다.

namespace ASPSample
{

    public class Product
    {
        string _Model;
        double _UnitPrice;

        public Product(string Model, double UnitPrice)
        {
            _Model = Model;
            _UnitPrice = UnitPrice;
        }

        // The product Model.
        public string Model
        {
            get {return _Model;}
            set {_Model = value;}
        }
            
        // The price of the each product.
        public double UnitPrice
        {
            get {return _UnitPrice;}
            set {_UnitPrice = value;}
        }
    }
}
Namespace ASPSample

    Public Class Product
        Private _Model As String
        Private _UnitPrice As Double

        ' The product Model.
        Public Property Model() As String
            Get
                Return _Model
            End Get
            Set(ByVal Value As String)
                _Model = Value
            End Set
        End Property

        ' The price of the each product.
        Public Property UnitPrice() As Double
            Get
                Return _UnitPrice
            End Get
            Set(ByVal Value As Double)
                _UnitPrice = Value
            End Set
        End Property


        Public Sub New(ByVal Model As String, ByVal UnitPrice As Double)
            _Model = Model
            _UnitPrice = UnitPrice
        End Sub

    End Class

End Namespace

설명

ASP.NET 웹 페이지의 데이터 바인딩 구문에서 이 클래스의 오버로드된 정적 Eval 메서드를 사용할 수 있습니다. 이렇게 하면 표준 데이터 바인딩보다 더 쉽게 작업할 수 있는 구문이 제공됩니다. 그러나 DataBinder.Eval 자동 형식 변환을 제공하므로 성능이 저하될 수 있습니다.

ASP.NET 데이터 바인딩, 식 및 구문에 대한 자세한 내용은 데이터베이스에 바인딩Data-Binding 식 개요 참조하세요.

.NET Framework 4.5부터 모델 바인딩을 사용하여 이전 버전의 데이터 바인딩을 통해 수행해야 했던 일부 작업을 간소화할 수 있습니다. Web Forms에서 모델 바인딩을 사용하는 방법에 대한 자습서 시리즈는 모델 바인딩 및 Web Forms를 참조하세요.

생성자

Name Description
DataBinder()

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

속성

Name Description
EnableCaching

런타임에 데이터 캐싱을 사용할 수 있는지 여부를 나타내는 값을 가져오거나 설정합니다.

메서드

Name Description
Equals(Object)

지정된 개체가 현재 개체와 같은지 여부를 확인합니다.

(다음에서 상속됨 Object)
Eval(Object, String, String)

런타임에 데이터 바인딩 식을 평가하고 결과 형식을 문자열로 지정합니다.

Eval(Object, String)

런타임에 데이터 바인딩 식을 평가합니다.

GetDataItem(Object, Boolean)

성공 또는 실패를 나타내는 개체의 선언된 데이터 항목을 검색합니다.

GetDataItem(Object)

개체의 선언된 데이터 항목을 검색합니다.

GetHashCode()

기본 해시 함수로 사용됩니다.

(다음에서 상속됨 Object)
GetIndexedPropertyValue(Object, String, String)

지정된 컨테이너에 대해 지정된 속성의 값을 검색한 다음 결과 형식을 지정합니다.

GetIndexedPropertyValue(Object, String)

지정된 컨테이너 및 탐색 경로의 속성 값을 검색합니다.

GetPropertyValue(Object, String, String)

지정된 개체의 지정된 속성 값을 검색한 다음 결과의 서식을 지정합니다.

GetPropertyValue(Object, String)

지정된 개체의 지정된 속성 값을 검색합니다.

GetType()

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

(다음에서 상속됨 Object)
IsBindableType(Type)

지정된 데이터 형식을 바인딩할 수 있는지 여부를 결정합니다.

MemberwiseClone()

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

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

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

(다음에서 상속됨 Object)

적용 대상

추가 정보