Repeater.OnItemDataBound Method
Raises the ItemDataBound event.
[Visual Basic] Protected Overridable Sub OnItemDataBound( _ ByVal e As RepeaterItemEventArgs _ ) [C#] protected virtual void OnItemDataBound( RepeaterItemEventArgs e ); [C++] protected: virtual void OnItemDataBound( RepeaterItemEventArgs* e ); [JScript] protected function OnItemDataBound( e : RepeaterItemEventArgs );
Parameters
- e
- The RepeaterItemEventArgs that contains the event data.
Remarks
Raising an event invokes the event handler through a delegate. For more information, see Raising an Event.
Notes to Inheritors: When overriding OnItemDataBound in a derived class, be sure to call the base class's OnItemDataBound method.
Example
[Visual Basic, C#] The following example illustrates a way to handle the ItemDataBound event of the Repeater. The data is modified after it is bound to an item in the Repeater but before it is rendered on the page.
[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 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> [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 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 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>
[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
Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family
See Also
Repeater Class | Repeater Members | System.Web.UI.WebControls Namespace | ItemDataBound | RepeaterItemEventArgs | RepeaterItemEventHandler