DataBinder Sınıf

Tanım

Veri bağlama ifadesi söz dizimini oluşturmak ve ayrıştırmak için hızlı uygulama geliştirme (RAD) tasarımcıları için destek sağlar. Bu sınıf devralınamaz.

public ref class DataBinder sealed
public sealed class DataBinder
type DataBinder = class
Public NotInheritable Class DataBinder
Devralma
DataBinder

Örnekler

Aşağıdaki örnek, bir denetimin alanlarını nesnelerden birini GetPropertyValueRepeater kullanarak ArrayList doldurmak için statik Product yöntemi kullanır. Eval yöntemi aynı söz dizimi ile uygulanabilir, ancak bu kadar hızlı çalışmaz.

Bu örnek, bir dize Product özelliğini ve sayısal Model bir özelliği kullanıma sunan özel UnitPrice bir sınıf kullanır.

<%@ 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>

Aşağıdaki kod özel Product sınıftır. Bu kod, App_Code dizininde Product.cs veya Product.vb gibi ayrı bir sınıf dosyasına eklenmelidir.

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

Açıklamalar

ASP.NET Web sayfasındaki veri bağlama söz diziminde bu sınıfın aşırı yüklenmiş statik Eval yöntemini kullanabilirsiniz. Bu, standart veri bağlamadan daha kolay bir söz dizimi sağlar. Ancak otomatik DataBinder.Eval tür dönüştürme sağladığından performansın düşmesine neden olabilir.

ASP.NET veri bağlama, ifadeler ve söz dizimi hakkında daha fazla bilgi için bkz. Veritabanlarına Bağlama ve Data-Binding İfadelere Genel Bakış.

.NET Framework 4.5'den başlayarak, önceki sürümlerde veri bağlama aracılığıyla gerçekleştirmeniz gereken bazı görevleri basitleştirmek için model bağlamayı kullanabilirsiniz. Web Forms ile model bağlama kullanma öğretici serisi için bkz. Model Bağlama ve Web Forms.

Oluşturucular

Name Description
DataBinder()

DataBinder sınıfının yeni bir örneğini başlatır.

Özellikler

Name Description
EnableCaching

Çalışma zamanında veri önbelleğe almanın etkinleştirilip etkinleştirilmediğini gösteren bir değer alır veya ayarlar.

Yöntemler

Name Description
Equals(Object)

Belirtilen nesnenin geçerli nesneye eşit olup olmadığını belirler.

(Devralındığı yer: Object)
Eval(Object, String, String)

Çalışma zamanında veri bağlama ifadelerini değerlendirir ve sonucu dize olarak biçimlendirer.

Eval(Object, String)

Çalışma zamanında veri bağlama ifadelerini değerlendirir.

GetDataItem(Object, Boolean)

Bir nesnenin bildirilen veri öğesini alır ve başarıyı veya başarısızlığı gösterir.

GetDataItem(Object)

Nesnenin bildirilen veri öğesini alır.

GetHashCode()

Varsayılan karma işlevi işlevi görür.

(Devralındığı yer: Object)
GetIndexedPropertyValue(Object, String, String)

Belirtilen kapsayıcı için belirtilen özelliğin değerini alır ve sonuçları biçimlendirır.

GetIndexedPropertyValue(Object, String)

Belirtilen kapsayıcının ve gezinti yolunun bir özelliğinin değerini alır.

GetPropertyValue(Object, String, String)

Belirtilen nesnenin belirtilen özelliğinin değerini alır ve sonuçları biçimlendirer.

GetPropertyValue(Object, String)

Belirtilen nesnenin belirtilen özelliğinin değerini alır.

GetType()

Geçerli örneğin Type alır.

(Devralındığı yer: Object)
IsBindableType(Type)

Belirtilen veri türünün bağlanıp bağlanamayacağını belirler.

MemberwiseClone()

Geçerli Objectbasit bir kopyasını oluşturur.

(Devralındığı yer: Object)
ToString()

Geçerli nesneyi temsil eden bir dize döndürür.

(Devralındığı yer: Object)

Şunlara uygulanır

Ayrıca bkz.