Export (0) Print
Expand All

Repeater.OnItemDataBound Method

Raises the ItemDataBound event.

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)

Protected Overridable Sub OnItemDataBound ( _
	e As RepeaterItemEventArgs _


Type: System.Web.UI.WebControls.RepeaterItemEventArgs

The RepeaterItemEventArgs object that contains the event data.

Raising an event invokes the event handler through a delegate. For more information, see Consuming Events.

Notes to Inheritors

When overriding OnItemDataBound in a derived class, be sure to call the base class's OnItemDataBound method.

The following example illustrates a way to handle the ItemDataBound event of the Repeater control. The data is modified after it is bound to an item in the Repeater control but before it is rendered on the page.

<%@ Page Language="VB" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<script language="VB" runat="server">

    Sub Page_Load(Sender As Object, e As EventArgs)

        If Not IsPostBack Then
            Dim values As New ArrayList()

            values.Add(New Evaluation("Razor Wiper Blades", "Good"))
            values.Add(New Evaluation("Shoe-So-Soft Softening Polish", "Poor"))
            values.Add(New Evaluation("DynaSmile Dental Fixative", "Fair"))

            Repeater1.DataSource = values
        End If
    End Sub

    Sub R1_ItemDataBound(Sender As Object, e As RepeaterItemEventArgs)

        ' This event is raised for the header, the footer, separators, and items.

        ' Execute the following logic for Items and Alternating Items.
        If (e.Item.ItemType = ListItemType.Item) Or _
            (e.Item.ItemType = ListItemType.AlternatingItem) Then

            If CType(e.Item.DataItem, Evaluation).Rating = "Good" Then
                CType(e.Item.FindControl("RatingLabel"), Label).Text = _
            End If
        End If
    End Sub

    Public Class Evaluation

        Private myProductid As String
        Private myRating As String        

        Public Sub New(newProductid As String, newRating As String)
            Me.myProductid = newProductid
            Me.myRating = newRating
        End Sub        

        Public ReadOnly Property ProductID() As String
                Return myProductid
            End Get
        End Property        

        Public ReadOnly Property Rating() As String
                Return myRating
            End Get
        End Property
    End Class

<html xmlns="http://www.w3.org/1999/xhtml" >
    <title>OnItemDataBound Example</title>

    <form id="form1" runat="server">

    <h3>OnItemDataBound Example</h3>

       <br />
       <asp:Repeater id="Repeater1" OnItemDataBound="R1_ItemDataBound" runat="server">
             <table border="1">
                   <td><b>Consumer Rating</b></td>

                <td> <asp:Label Text='<%# DataBinder.Eval(Container.DataItem, "ProductID") %>' Runat="server"/> </td>
                <td> <asp:Label id="RatingLabel" Text='<%# DataBinder.Eval(Container.DataItem, "Rating") %>' Runat="server"/> </td>


       <br />


.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

© 2014 Microsoft