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 nesne kullanarak ArrayList Product bir Repeater denetimin alanlarını doldurmak için statik GetPropertyValue yöntemi kullanır. Eval yöntemi aynı söz dizimiyle uygulanabilir, ancak bu kadar hızlı çalışmaz.

Bu örnekte, bir dize Model özelliğini ve sayısal UnitPrice bir özelliği kullanıma sunan özel Product bir sınıf kullanılı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ıfıdı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

Bir ASP.NET Web sayfasında veri bağlama söz diziminde bu sınıfın aşırı yüklenmiş statik Eval yöntemini kullanabilirsiniz. Bu, standart veri bağlamaya kıyasla daha kolay bir söz dizimi sağlar. Ancak, DataBinder.Eval otomatik tür dönüştürme sağladığından performansın yavaşlamasına 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 Veri Bağlama İfadelerine Genel Bakış.

.NET Framework 4.5 sürümünden 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

DataBinder()

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

Özellikler

EnableCaching

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

Yöntemler

Equals(Object)

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

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

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

Eval(Object, String, String)

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

GetDataItem(Object)

Nesnenin bildirilen veri öğesini alır.

GetDataItem(Object, Boolean)

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

GetHashCode()

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

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

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

GetIndexedPropertyValue(Object, String, String)

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

GetPropertyValue(Object, String)

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

GetPropertyValue(Object, String, String)

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

GetType()

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

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

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

MemberwiseClone()

Geçerli Objectöğesinin sığ bir kopyasını oluşturur.

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

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

(Devralındığı yer: Object)

Şunlara uygulanır

Ayrıca bkz.