Export (0) Print
Expand All

Repeater.DataMember Property

Gets or sets the specific table in the DataSource to bind to the control.

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

public virtual string DataMember { get; set; }
/** @property */
public String get_DataMember ()

/** @property */
public void set_DataMember (String value)

public function get DataMember () : String

public function set DataMember (value : String)

Property Value

A string that specifies a table in the DataSource.

If the data source specified by the DataSource property contains multiple sources of data, use the DataMember property to specify the specific source to bind to the control. For example, if you have a System.Data.DataSet with multiple tables, you must specify which table to bind to the control. After you have specified the data source, use the DataBind method to bind the data source to the control.

The value of this property is stored in view state.

The following example demonstrates how to use the DataMember property to specify a table in the DataSource to bind to the Repeater control.

<%@ Page Language="C#" AutoEventWireup="True" %>
<%@ Import Namespace = "System.Data" %> 
 <html>
 <head>
    <script language="C#" runat="server">
       void Page_Load(Object Sender, EventArgs e) {
 
          if (!IsPostBack) {
 
             DataTable dt1 = new DataTable("Dt1");
 
             DataRow dr;
  
             dt1.Columns.Add(new DataColumn("IntegerValue", typeof(Int32)));
             dt1.Columns.Add(new DataColumn("StringValue", typeof(string)));
             dt1.Columns.Add(new DataColumn("CurrencyValue", typeof(double)));
          
             DataSet ds= new DataSet("ds1");            
 
             ds.Tables.Add(dt1);
 
             for (int i = 0; i < 9; i++) {
                dr = dt1.NewRow();
 
                dr[0] = i;
                dr[1] = "Item " + i.ToString();
                dr[2] = 1.23 * (i+1);
   
                dt1.Rows.Add(dr);
             }
 
             DataTable dt2 = new DataTable("Dt2");
  
             dt2.Columns.Add(new DataColumn("IntegerValue", typeof(Int32)));
             dt2.Columns.Add(new DataColumn("StringValue", typeof(string)));
             dt2.Columns.Add(new DataColumn("CurrencyValue", typeof(double)));           
 
             ds.Tables.Add(dt2);
 
             for (int i = 0; i < 9; i++) {
                dr = dt2.NewRow();
 
                dr[0] = i;
                dr[1] = "Item " + i.ToString();
                dr[2] = 4.56 * (i+1);
   
                dt2.Rows.Add(dr);
             }
 
             Repeater1.DataSource = ds;
             Repeater1.DataMember = "Dt1";
             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> 
                   <%# DataBinder.Eval(Container.DataItem, "StringValue") %> 
                </td>
                <td> 
                   <%# DataBinder.Eval(Container.DataItem, "CurrencyValue") %> 
                </td>
             </tr>
          </ItemTemplate>
             
          <FooterTemplate>
             </table>
          </FooterTemplate>
             
       </asp:Repeater>
         
    </form>
 </body>
 </html>
 

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

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft