DataBinder 클래스

정의

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

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

예제

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

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

<%@ 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 데이터 바인딩, 식 및 구문에 대 한 자세한 내용은 참조 하세요. 데이터베이스를 바인딩할 하 고 데이터 바인딩 식을 개요합니다.

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

생성자

DataBinder()

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

속성

EnableCaching

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

메서드

Equals(Object)

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

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

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

Eval(Object, String, String)

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

GetDataItem(Object)

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

GetDataItem(Object, Boolean)

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

GetHashCode()

기본 해시 함수로 작동합니다.

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

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

GetIndexedPropertyValue(Object, String, String)

지정된 컨테이너의 지정된 속성 값을 검색하여 결과 형식을 지정합니다.

GetPropertyValue(Object, String)

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

GetPropertyValue(Object, String, String)

지정된 개체의 지정된 속성 값을 검색하여 결과 형식을 지정합니다.

GetType()

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

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

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

MemberwiseClone()

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

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

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

(다음에서 상속됨 Object)

적용 대상

추가 정보