Export (0) Print
Expand All

Repeater.DataMember Property

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

[Visual Basic]
Public Overridable Property DataMember As String
[C#]
public virtual string DataMember {get; set;}
[C++]
public: __property virtual String* get_DataMember();
public: __property virtual void set_DataMember(String*);
[JScript]
public function get DataMember() : String;
public function set DataMember(String);

Property Value

A string that specifies a table in the DataSource.

Remarks

If the DataSource contains multiple tables, use this property to specify the table to bind to the Repeater.

Example

[Visual Basic, C#] The following example demonstrates how to use the DataMember property to specify a table in the DataSource to bind to the Repeater control.

[Visual Basic] 
<%@ Page Language="VB" AutoEventWireup="True" %>
<%@ Import Namespace = "System.Data" %> 
 <html>
 <head>
    <script language="VB" runat="server">

    Sub Page_Load(Sender As Object, e As EventArgs)
        
        If Not IsPostBack Then
            
            Dim dt1 As New DataTable("Dt1")
            
            Dim dr As DataRow
            
            dt1.Columns.Add(New DataColumn("IntegerValue", GetType(Int32)))
            dt1.Columns.Add(New DataColumn("StringValue", GetType(String)))
            dt1.Columns.Add(New DataColumn("CurrencyValue", GetType(Double)))
            
            Dim ds As New DataSet("ds1")
            
            ds.Tables.Add(dt1)
            
            Dim i As Integer
            For i = 0 To 8
                dr = dt1.NewRow()
                
                dr(0) = i
                dr(1) = "Item " + i.ToString()
                dr(2) = 1.23 *(i + 1)
                
                dt1.Rows.Add(dr)
            Next i
            
            Dim dt2 As New DataTable("Dt2")
            
            dt2.Columns.Add(New DataColumn("IntegerValue", GetType(Int32)))
            dt2.Columns.Add(New DataColumn("StringValue", GetType(String)))
            dt2.Columns.Add(New DataColumn("CurrencyValue", GetType(Double)))
            
            ds.Tables.Add(dt2)
            
            For i = 0 To 8
                dr = dt2.NewRow()
                
                dr(0) = i
                dr(1) = "Item " + i.ToString()
                dr(2) = 4.56 *(i + 1)
                
                dt2.Rows.Add(dr)
            Next i
            
            Repeater1.DataSource = ds
            Repeater1.DataMember = "Dt1"
            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> 
                   <%# DataBinder.Eval(Container.DataItem, "StringValue") %> 
                </td>
                <td> 
                   <%# DataBinder.Eval(Container.DataItem, "CurrencyValue") %> 
                </td>
             </tr>
          </ItemTemplate>
             
          <FooterTemplate>
             </table>
          </FooterTemplate>
             
       </asp:Repeater>
         
    </form>
 </body>
 </html>
 

[C#] 
<%@ 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>
 

[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 | DataSource

Show:
© 2014 Microsoft