This documentation is archived and is not being maintained.

Repeater.ItemDataBound Event

Occurs after an item in the Repeater control is data-bound but before it is rendered on the page.

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

'Declaration
Public Event ItemDataBound As RepeaterItemEventHandler
'Usage
Dim instance As Repeater
Dim handler As RepeaterItemEventHandler

AddHandler instance.ItemDataBound, handler

/** @event */
public void add_ItemDataBound (RepeaterItemEventHandler value)

/** @event */
public void remove_ItemDataBound (RepeaterItemEventHandler value)

JScript supports the use of events, but not the declaration of new ones.

This event is raised when an item in the Repeater control is data-bound.

For more information about handling events, see Consuming Events.

The following example demonstrates how to specify and code a handler for 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" %>
<html>
 <head>
    <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
            Repeater1.DataBind()
        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 = _
                    "<b>***Good***</b>"
            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
            Get
                Return myProductid
            End Get
        End Property        
        
        Public ReadOnly Property Rating() As String
            Get
                Return myRating
            End Get
        End Property
    End Class
 
    </script>
 
 </head>
 <body>
 
    <h3>OnItemDataBound Example</h3>
 
    <form runat=server>
 
       <p>
       <asp:Repeater id=Repeater1 OnItemDataBound="R1_ItemDataBound" runat="server">
          <HeaderTemplate>
             <table border=1>
                <tr>
                   <td><b>Product</b></td>
                   <td><b>Consumer Rating</b></td>
                </tr>
          </HeaderTemplate>
             
          <ItemTemplate>
             <tr>
                <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>
             </tr>
          </ItemTemplate>
             
          <FooterTemplate>
             </table>
          </FooterTemplate>
             
       </asp:Repeater>
       <p>
 
    </form>
 </body>
 </html>
    

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

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

.NET Framework

Supported in: 2.0, 1.1, 1.0
Show: