다음을 통해 공유


Repeater.OnItemDataBound(RepeaterItemEventArgs) 메서드

정의

ItemDataBound 이벤트를 발생시킵니다.

protected:
 virtual void OnItemDataBound(System::Web::UI::WebControls::RepeaterItemEventArgs ^ e);
protected virtual void OnItemDataBound (System.Web.UI.WebControls.RepeaterItemEventArgs e);
abstract member OnItemDataBound : System.Web.UI.WebControls.RepeaterItemEventArgs -> unit
override this.OnItemDataBound : System.Web.UI.WebControls.RepeaterItemEventArgs -> unit
Protected Overridable Sub OnItemDataBound (e As RepeaterItemEventArgs)

매개 변수

e
RepeaterItemEventArgs

이벤트 데이터를 포함하는 RepeaterItemEventArgs 개체입니다.

예제

다음 예제에서는 컨트롤의 이벤트를 처리 ItemDataBound 하는 방법을 보여 줍니다 Repeater . 데이터는 컨트롤의 항목에 Repeater 바인딩된 후 페이지에 렌더링되기 전에 수정됩니다.

<%@ Page Language="C#" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
 <head>
    <title>OnItemDataBound Example</title>
<script language="C#" runat="server">
       void Page_Load(Object Sender, EventArgs e) {
 
          if (!IsPostBack) {
             ArrayList values = 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();
          }
       }
 
       void R1_ItemDataBound(Object Sender, RepeaterItemEventArgs e) {
                              
          // 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 || e.Item.ItemType == ListItemType.AlternatingItem) {
                 
             if (((Evaluation)e.Item.DataItem).Rating == "Good") {
                ((Label)e.Item.FindControl("RatingLabel")).Text= "<b>***Good***</b>";
             }
          }
       }    
 
       public class Evaluation {
         
          private string productid;
          private string rating;
 
          public Evaluation(string productid, string rating) {
             this.productid = productid;
             this.rating = rating;
          }
 
          public string ProductID {
             get {
                return productid;
             }
          }
 
          public string Rating {
             get {
                return rating;
             }
          }
       }
 
    </script>
 
 </head>
 <body>
 
    <h3>OnItemDataBound Example</h3>
 
    <form id="form1" runat="server">
 
       <br />
       <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>
       <br />
 
    </form>
 </body>
 </html>
<%@ Page Language="VB" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<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>
<html xmlns="http://www.w3.org/1999/xhtml" >
 <head>
    <title>OnItemDataBound Example</title>
 
 </head>
 <body>
    <form id="form1" runat="server">
 
    <h3>OnItemDataBound Example</h3>
 
  
       <br />
       <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>
       <br />
 
    </form>
 </body>
 </html>

설명

이벤트가 발생하면 대리자를 통해 이벤트 처리기가 호출됩니다. 이벤트를 처리 하는 방법에 대 한 자세한 내용은 참조 하세요. 이벤트 처리 및 발생합니다.

상속자 참고

재정의 하는 경우 OnItemDataBound(RepeaterItemEventArgs) 파생된 클래스에서 호출 해야 기본 클래스의 OnItemDataBound(RepeaterItemEventArgs) 메서드.

적용 대상

추가 정보