Export (0) Print
Expand All

Repeater.DataSource Property

Gets or sets the data source that provides data for populating the list.

[Visual Basic]
Public Overridable Property DataSource As Object
[C#]
public virtual object DataSource {get; set;}
[C++]
public: __property virtual Object* get_DataSource();
public: __property virtual void set_DataSource(Object*);
[JScript]
public function get DataSource() : Object;
public function set DataSource(Object);

Property Value

A data source that provides data for populating the list. The default is a null reference (Nothing in Visual Basic).

Exceptions

Exception Type Condition
ArgumentException The DataSource specified is not a supported source of data for the Repeater.

Remarks

Use this property to specify the source of data to populate the Repeater control. The DataSource can be any System.Collections.IEnumerable derived object such as a System.Data.DataView for accessing databases, a System.Collections.ArrayList, a System.Collections.Hashtable, or an array.

Example

[Visual Basic, C#] The following example demonstrates how to specify the DataSource of the Repeater when the page is loaded.

[Visual Basic] 
<%@ Page Language="VB" AutoEventWireup="True" %>
<html>
 <head>
    <script runat="server">

        Sub Page_Load(Sender As Object, e As EventArgs)
            
            If Not IsPostBack Then
                Dim values As New ArrayList()
                
                values.Add("Apple")
                values.Add("Orange")
                values.Add("Pear")
                values.Add("Banana")
                values.Add("Grape")
                
                ' Set the DataSource of the Repeater. 
                Repeater1.DataSource = values
                Repeater1.DataBind()
            End If
        End Sub
        
    </script>
 
 </head>
 <body>
 
    <h3>Repeater Example</h3>
 
    <form runat=server>
 
       <b>Repeater1:</b>
       <p>
         
       <asp:Repeater id=Repeater1 runat="server">
             
          <HeaderTemplate>
             <table border=1>
          </HeaderTemplate>
 
          <ItemTemplate>
             <tr>
                <td> <%# Container.DataItem %> </td>
             </tr>
          </ItemTemplate>
             
          <FooterTemplate>
             </table>
          </FooterTemplate>
             
       </asp:Repeater>
       <p>
         
    </form>
 </body>
 </html>
 

[C#] 
<%@ Page Language="C#" AutoEventWireup="True" %>
<html>
 <head>
    <script runat="server">
       void Page_Load(Object Sender, EventArgs e) {
 
          if (!IsPostBack) {
             ArrayList values = new ArrayList();
 
             values.Add("Apple");
             values.Add("Orange");
             values.Add("Pear");
             values.Add("Banana");
             values.Add("Grape");
 
             // Set the DataSource of the Repeater. 
             Repeater1.DataSource = values;
             Repeater1.DataBind();
          }
       }
    </script>
 
 </head>
 <body>
 
    <h3>Repeater Example</h3>
 
    <form runat=server>
 
       <b>Repeater1:</b>
       <p>
         
       <asp:Repeater id=Repeater1 runat="server">
             
          <HeaderTemplate>
             <table border=1>
          </HeaderTemplate>
 
          <ItemTemplate>
             <tr>
                <td> <%# Container.DataItem %> </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 Language Filter 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 | DataMember

Show:
© 2014 Microsoft