RepeaterCommandEventHandler Delegate
Represents the method that will handle the ItemCommand event of a Repeater.
[Visual Basic] <Serializable> Public Delegate Sub RepeaterCommandEventHandler( _ ByVal source As Object, _ ByVal e As RepeaterCommandEventArgs _ ) [C#] [Serializable] public delegate void RepeaterCommandEventHandler( object source, RepeaterCommandEventArgs e ); [C++] [Serializable] public __gc __delegate void RepeaterCommandEventHandler( Object* source, RepeaterCommandEventArgs* e );
[JScript] In JScript, you can use the delegates in the .NET Framework, but you cannot define your own.
Parameters [Visual Basic, C#, C++]
The declaration of your event handler must have the same parameters as the RepeaterCommandEventHandler delegate declaration.
- source
- The source of the event.
- e
- A RepeaterCommandEventArgs that contains the event data.
Remarks
When you create a RepeaterCommandEventHandler delegate, you identify the method that will handle the event. To associate the event with your event handler, add an instance of the delegate to the event. The event handler is called whenever the event occurs, unless you remove the delegate. For more information about event handler delegates, see Events and Delegates.
For more information about handling events, see Consuming Events.
Example
[Visual Basic, C#] The following example demonstrates how to specify and code a handler for the ItemCommand event of the Repeater. Information about the button is displayed when a Button control within the Repeater is clicked.
[Visual Basic] <%@ 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 PositionData("Microsoft", "Msft")) values.Add(New PositionData("Intel", "Intc")) values.Add(New PositionData("Dell", "Dell")) Repeater1.DataSource = values Repeater1.DataBind() End If End Sub Sub R1_ItemCommand(Sender As Object, e As RepeaterCommandEventArgs) Label2.Text = "The " & CType(e.CommandSource, Button).Text & _ " button has just been clicked; <br>" 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> <h3>Repeater Example</h3> <form runat=server> <b>Repeater1:</b> <p> <asp:Repeater id=Repeater1 OnItemCommand="R1_ItemCommand" runat="server"> <HeaderTemplate> <table border=1> <tr> <td><b>Company</b></td> <td><b>Symbol</b></td> </tr> </HeaderTemplate> <ItemTemplate> <tr> <td> <%# DataBinder.Eval(Container.DataItem, "Name") %> </td> <td> <ASP:Button Text=<%# DataBinder.Eval(Container.DataItem, "Ticker") %> runat="server" /></td> </tr> </ItemTemplate> <FooterTemplate> </table> </FooterTemplate> </asp:Repeater> <p> <asp:Label id=Label2 font-name="Verdana" ForeColor="Green" font-size="10pt" runat="server"/> </form> </body> </html> [C#] <%@ Page Language="C#" AutoEventWireup="True" %> <html> <head> <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(); } } void R1_ItemCommand(Object Sender, RepeaterCommandEventArgs e) { Label2.Text = "The " + ((Button)e.CommandSource).Text + " button has just been clicked; <br>"; } 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> <h3>Repeater Example</h3> <form runat=server> <b>Repeater1:</b> <p> <asp:Repeater id=Repeater1 OnItemCommand="R1_ItemCommand" runat="server"> <HeaderTemplate> <table border=1> <tr> <td><b>Company</b></td> <td><b>Symbol</b></td> </tr> </HeaderTemplate> <ItemTemplate> <tr> <td> <%# DataBinder.Eval(Container.DataItem, "Name") %> </td> <td> <ASP:Button Text=<%# DataBinder.Eval(Container.DataItem, "Ticker") %> runat="server" /></td> </tr> </ItemTemplate> <FooterTemplate> </table> </FooterTemplate> </asp:Repeater> <p> <asp:Label id=Label2 font-name="Verdana" ForeColor="Green" font-size="10pt" runat="server"/> </form> </body> </html>
[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Namespace: System.Web.UI.WebControls
Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family
Assembly: System.Web (in System.Web.dll)
See Also
System.Web.UI.WebControls Namespace | Repeater | ItemCommand | RepeaterCommandEventArgs