Export (0) Print
Expand All

Repeater.OnDataBinding Method

This method supports the .NET Framework infrastructure and is not intended to be used directly from your code.

Raises the DataBinding event.

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

protected override void OnDataBinding (
	EventArgs e
)
protected void OnDataBinding (
	EventArgs e
)
protected override function OnDataBinding (
	e : EventArgs
)
Not applicable.

Parameters

e

An EventArgs object that contains the event data.

The following code examples demonstrate how to override the OnDataBinding method in a custom server control so that if the event argument is a command type, the Repeater control always calls the OnItemCommand and bubbles up the event, or returns false and cancels the event.

<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.CS.Controls" Assembly="Samples.AspNet.CS" %>
<%@ 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>Custom Repeater - OnDataBinding - 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 - OnDataBinding - C# Example</h3>
      <aspSample:CustomRepeaterOnDataBinding 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:CustomRepeaterOnDataBinding>
    </form>
  </body>
</html>

<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.JSL.Controls" Assembly="Samples.AspNet.JSL" %>
<%@ Page Language="VJ#" 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 - OnDataBinding - VJ# Example</title>
    <script language="VJ#" runat="server">
        void Page_Load(Object Sender, EventArgs e) 
        {
            if (!get_IsPostBack()) {
                ArrayList values =  new ArrayList();
                values.Add(new PositionData("Microsoft", "Msft"));
                values.Add(new PositionData("Intel", "Intc"));
                values.Add(new PositionData("Dell", "Dell"));
                Repeater1.set_DataSource(values);
                Repeater1.DataBind();
            }
        } //Page_Load

        public class PositionData
        {
            private String name;
            private String ticker;
            
            public PositionData(String name, String ticker) 
            {
                this.name = name;
                this.ticker = ticker;
            } //PositionData

            /** @property 
             */
            public String get_Name()
            {
                return name;
            } //get_Name

            /** @property 
             */
            public String get_Ticker()
            {
                return ticker;
            } //get_Ticker
        } //PositionData
    </script>
  </head>
  <body>
    <form id="Form1" method="post" runat="server">
      <h3>Custom Repeater - OnDataBinding - VJ# Example</h3>
      <aspSample:CustomRepeaterOnDataBinding 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.get_DataItem(), "Name") %></td>
            <td> <%# DataBinder.Eval(Container.get_DataItem(), "Ticker") %></td>
          </tr>
        </ItemTemplate>
        <FooterTemplate>
            </table>
        </FooterTemplate>
      </aspSample:CustomRepeaterOnDataBinding>
    </form>
  </body>
</html>

using System.Web;
using System.Security.Permissions;

namespace Samples.AspNet.CS.Controls
{
  [AspNetHostingPermission(SecurityAction.Demand, Level=AspNetHostingPermissionLevel.Minimal)]
  public sealed class CustomRepeaterOnDataBinding : System.Web.UI.WebControls.Repeater
  {
    protected override void OnDataBinding(System.EventArgs e)
    {
      // Raise the OnDataBinding event.
      base.OnDataBinding(e);

      // Clear out the controls collection and child viewstate.
      this.Controls.Clear();
      this.ClearChildViewState();

      // Create a new control hierarchy.
      this.CreateControlHierarchy(true);
      this.ChildControlsCreated = true;
    }
  }
}

package Samples.AspNet.JSL.Controls; 

public class CustomRepeaterOnDataBinding
    extends System.Web.UI.WebControls.Repeater
{
    protected void OnDataBinding(System.EventArgs e)
    {
        // Raise the OnDataBinding event.
        super.OnDataBinding(e);
        // Clear out the controls collection and child viewstate.
        this.get_Controls().Clear();
        this.ClearChildViewState();
        // Create a new control hierarchy.
        this.CreateControlHierarchy(true);
        this.set_ChildControlsCreated(true);
    } //OnDataBinding
} //CustomRepeaterOnDataBinding

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

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft