다음을 통해 공유


Repeater.OnBubbleEvent(Object, EventArgs) 메서드

정의

EventArgs 매개 변수가 ItemCommand의 인스턴스인 경우 RepeaterCommandEventArgs 이벤트를 발생시킵니다.

protected:
 override bool OnBubbleEvent(System::Object ^ sender, EventArgs ^ e);
protected override bool OnBubbleEvent (object sender, EventArgs e);
override this.OnBubbleEvent : obj * EventArgs -> bool
Protected Overrides Function OnBubbleEvent (sender As Object, e As EventArgs) As Boolean

매개 변수

sender
Object

이벤트 소스입니다.

e
EventArgs

이벤트 데이터가 포함된 EventArgs 개체입니다.

반환

ItemCommand가 발생되었으면 true이고, 그렇지 않으면 false입니다.

예제

다음 코드 예제에서는 재정의 OnDataBinding 하는 방법을 보여 줍니다는 메서드를 사용자 지정 서버 컨트롤에서 이벤트 인수는 명령 형식인 Repeater 경우 컨트롤은 항상 호출 OnItemCommand 하 고 이벤트를 버블, 또는 반환 false 하 고 이벤트를 취소 합니다.

<%@ Page Language="C#" AutoEventWireup="True" %>
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.CS.Controls" Assembly="Samples.AspNet.CS" %>
<!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>Custom Repeater - OnBubbleEvent - C# Example</title>
    <script language="C#" runat="server">
      void Page_Load(Object Sender, EventArgs e) 
      {
        if (!IsPostBack) 
        {
          ArrayList values = new ArrayList();
          values.Add(new PositionData("Microsoft", "Msft"));
          values.Add(new PositionData("Intel", "Intc"));
          values.Add(new PositionData("Dell", "Dell"));

          Repeater1.DataSource = values;
          Repeater1.DataBind();
        }
      }

      public class PositionData 
      {
        private string name;
        private string ticker;

        public PositionData(string name, string ticker) 
        {
          this.name = name;
          this.ticker = ticker;
        }

        public string Name 
        {
          get 
          {
            return name;
          }
        }

        public string Ticker 
        {
          get 
          {
            return ticker;
          }
        }
      }
    </script>
  </head>
  <body>
    <form id="Form1" method="post" runat="server">
      <h3>Custom Repeater - OnBubbleEvent - C# Example</h3>
      <aspSample:CustomRepeaterOnBubbleEvent id="Repeater1" runat="server">
        <HeaderTemplate>
          <table border="1" cellpadding="4" cellspacing="0">
            <tr>
              <th>Company</th>
              <th>Symbol</th>
            </tr>
        </HeaderTemplate>
        <ItemTemplate>
          <tr>
            <td> <%# DataBinder.Eval(Container.DataItem, "Name") %></td>
            <td> <%# DataBinder.Eval(Container.DataItem, "Ticker") %></td>
          </tr>
        </ItemTemplate>
        <FooterTemplate>
            </table>
        </FooterTemplate>
      </aspSample:CustomRepeaterOnBubbleEvent>
    </form>
  </body>
</html>
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.VB.Controls" Assembly="Samples.AspNet.VB" %>
<%@ 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">
<html xmlns="http://www.w3.org/1999/xhtml" >
    <head>
        <title>Custom Repeater - OnBubbleEvent - VB.NET Example</title>
        <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 PositionData("Microsoft", "Msft"))
                    values.Add(New PositionData("Intel", "Intc"))
                    values.Add(New PositionData("Dell", "Dell"))
                    
                    Repeater1.DataSource = values
                    Repeater1.DataBind()
                End If
            End Sub

            Public Class PositionData
                
                Private myName As String
                Private myTicker As String        
                
                Public Sub New(newName As String, newTicker As String)
                    Me.myName = newName
                    Me.myTicker = newTicker
                End Sub        
                
                Public ReadOnly Property Name() As String
                    Get
                        Return myName
                    End Get
                End Property        
                
                Public ReadOnly Property Ticker() As String
                    Get
                        Return myTicker
                    End Get
                End Property
            End Class
        </script>
    </head>
    <body>
        <form id="Form1" method="post" runat="server">
            <h3>Custom Repeater - OnBubbleEvent - VB.NET Example</h3>
            
            <aspSample:CustomRepeaterOnBubbleEvent id="Repeater1" runat="server" >
                    <HeaderTemplate>
                        <table border="1" cellpadding="4" cellspacing="0">
                            <tr>
                                <th>Company</th>
                                <th>Symbol</th>
                            </tr>
                    </HeaderTemplate>
                    <ItemTemplate>
                        <tr>
                            <td> <%# DataBinder.Eval(Container.DataItem, "Name") %></td>
                            <td> <%# DataBinder.Eval(Container.DataItem, "Ticker") %></td>
                        </tr>
                    </ItemTemplate>
                    <FooterTemplate>
                        </table>
                    </FooterTemplate>
                </aspSample:CustomRepeaterOnBubbleEvent>
        </form>
    </body>
</html>
using System.Web;
using System.Security.Permissions;

namespace Samples.AspNet.CS.Controls
{
  [AspNetHostingPermission(SecurityAction.Demand, Level=AspNetHostingPermissionLevel.Minimal)]
  public sealed class CustomRepeaterOnBubbleEvent : System.Web.UI.WebControls.Repeater
  {
    protected override bool OnBubbleEvent(object source, System.EventArgs args)
    {
      // If the EventArgs are of type RepeaterCommandEventArgs,
      // then call the OnItemCommand event handler and return true (bubble up the event)
      // else return false (don't bubble up the event).
      bool isHandled = false;
      if (args is System.Web.UI.WebControls.RepeaterCommandEventArgs) 
      {
        this.OnItemCommand((System.Web.UI.WebControls.RepeaterCommandEventArgs)args);
        isHandled = true;
      }
      return isHandled;
    }
  }
}
Imports System.Web
Imports System.Security.Permissions

Namespace Samples.AspNet.VB.Controls
    <AspNetHostingPermission(SecurityAction.Demand, Level:=AspNetHostingPermissionLevel.Minimal)> _
    Public NotInheritable Class CustomRepeaterOnBubbleEvent
        Inherits System.Web.UI.WebControls.Repeater

        Protected Overrides Function OnBubbleEvent(ByVal [source] As Object, ByVal args As System.EventArgs) As Boolean

            ' If the EventArgs are of type RepeaterCommadnEventArgs,
            ' then call the OnItemCommand event handler and return true (bubble up the event)
            ' else return false (don't bubble up the event).
            Dim isHandled As Boolean = False
            If TypeOf args Is System.Web.UI.WebControls.RepeaterCommandEventArgs Then
                Me.OnItemCommand(CType(args, System.Web.UI.WebControls.RepeaterCommandEventArgs))
                isHandled = True
            End If
            Return isHandled
        End Function
    End Class
End Namespace

적용 대상

추가 정보