次の方法で共有


BaseDataList.DataMember プロパティ

データ リスト コントロールに連結する複数メンバ データ ソースの特定のデータ メンバを取得または設定します。

名前空間: System.Web.UI.WebControls
アセンブリ: System.Web (system.web.dll 内)

構文

'宣言
<ThemeableAttribute(False)> _
Public Property DataMember As String
'使用
Dim instance As BaseDataList
Dim value As String

value = instance.DataMember

instance.DataMember = value
[ThemeableAttribute(false)] 
public string DataMember { get; set; }
[ThemeableAttribute(false)] 
public:
property String^ DataMember {
    String^ get ();
    void set (String^ value);
}
/** @property */
public String get_DataMember ()

/** @property */
public void set_DataMember (String value)
public function get DataMember () : String

public function set DataMember (value : String)
適用できません。

プロパティ値

複数メンバ データ ソースのデータ メンバ。既定値は String.Empty です。

解説

DataMember プロパティを使用して、リスト コントロールに連結する複数メンバ データ ソースのメンバを指定します。たとえば、DataSource プロパティで複数のテーブルを持つデータ ソースを指定した場合、DataMember プロパティを使用して、データ リスト コントロールにバインドするテーブルを指定します。

このプロパティを、テーマまたはスタイル シート テーマを使用して設定することはできません。詳細については、ThemeableAttribute のトピックおよび「ASP.NET のテーマとスキンの概要」を参照してください。

使用例

DataMember プロパティを使用して、DataGrid コントロールにバインドする DataSet オブジェクト内のテーブルを指定する方法を、次のコード例に示します。

<%@ Page Language="VB" AutoEventWireup="True" %>
<%@ Import Namespace = "System.Data"  %>

<!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 runat="server">
    <title> BaseDataList DataMember Example </title>
<script runat="server">

      ' Create sample data for the DataGrid control with two tables,
      ' Employee and Customer.
      Function CreateDataSet() As DataSet
    
         ' Create a table to store employee values.
         Dim EmployeeTable As DataTable = New DataTable("Employee")
         Dim TempDataRow As DataRow
   
         ' Define the columns for the Employee table.
         EmployeeTable.Columns.Add( _
            New DataColumn("EmployeeName", GetType(String)))
         EmployeeTable.Columns.Add( _
            New DataColumn("EmployeeID", GetType(Integer)))

         ' Populate the Employee table.
         Dim i As Integer

         For i=1 To 5 
         
            TempDataRow = EmployeeTable.NewRow()
            TempDataRow(0) = "Employee " & i.ToString()
            TempDataRow(1) = (i+1700)

            EmployeeTable.Rows.Add(TempDataRow)

         Next

         ' Create a table to store customer values.
         Dim CustomerTable As DataTable = New DataTable("Customer")

         ' Define the columns for the Customer table.
         CustomerTable.Columns.Add( _
            New DataColumn("CustomerName", GetType(String)))
         CustomerTable.Columns.Add( _
            New DataColumn("CustomerID", GetType(Integer)))

         ' Populate the Customer table.
         For i=1 To 5  

            TempDataRow = CustomerTable.NewRow()
            TempDataRow(0) = "Customer " & i.ToString()
            TempDataRow(1) = (i+1700)

            CustomerTable.Rows.Add(TempDataRow)
         
         Next

         ' Create a DataSet and add the Employee and Customer tables.
         Dim ds As DataSet = New DataSet()
         ds.Tables.Add(EmployeeTable)
         ds.Tables.Add(CustomerTable)

         Return ds

      End Function
             
      Sub Page_Load(sender As Object, e As EventArgs) 

         ' The data source only needs to be bound to the DataList  
         ' control the first time the page is accessed.    
         If Not IsPostBack Then

            ' Create the sample data for the DataList control.
            ItemsGrid.DataSource = CreateDataSet()

            ' The data source in this example contains multiple tables.  
            ' Specify which table to display in the DataList control. 
            ItemsGrid.DataMember = "Customer"

            ' Bind the data source to the control.
            ItemsGrid.DataBind()

         End If

      End Sub

      Sub Index_Change(sender As Object, e As EventArgs) 

         ' Create the sample data for the DataList control.
         ItemsGrid.DataSource = CreateDataSet()

         ' The data source in this example contains multiple tables. 
         ' Specify which table to display in the DataList control 
         ' based on the user's selection from the DropDownList control. 
         ItemsGrid.DataMember = SourceList.SelectedItem.Text

         ' Bind the data source to the control. 
         ItemsGrid.DataBind()

      End Sub

   </script>

</head>
<body>

   <form id="form1" runat="server">

      <h3> BaseDataList DataMember Example </h3>
      
      <asp:DataGrid id="ItemsGrid"
           AutoGenerateColumns="True" 
           runat="server">

         <headerstyle backcolor="#00aaaa"/>
</asp:DataGrid>

      <br /><br />

      Select the data source: <br />

      <asp:DropDownList id="SourceList"
           AutoPostBack="True"
           OnSelectedIndexChanged="Index_Change"
           runat="server">

         <asp:Listitem Selected="True">Customer</asp:Listitem>
         <asp:Listitem>Employee</asp:Listitem>

      </asp:DropDownList>

   </form>
 
</body>

</html>
<%@ Page Language="C#" AutoEventWireup="True" %>
<%@ Import Namespace = "System.Data"  %>

<!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 runat="server">
    <title> BaseDataList DataMember Example </title>
<script runat="server">

      // Create sample data for the DataGrid control with two tables, 
      // Employee and Customer.
      DataSet CreateDataSet()
      {
    
         // Create a table to store employee values.
         DataTable EmployeeTable = new DataTable("Employee");
         DataRow TempDataRow;
   
         // Define the columns for the Employee table.
         EmployeeTable.Columns.Add(
            new DataColumn("EmployeeName", typeof(string)));
         EmployeeTable.Columns.Add(
            new DataColumn("EmployeeID", typeof(int)));

         // Populate the Employee table.
         for (int i=1; i<=5; i++) 
         {
            TempDataRow = EmployeeTable.NewRow();
            TempDataRow[0] = "Employee " + i.ToString();
            TempDataRow[1] = (i+1700);

            EmployeeTable.Rows.Add(TempDataRow);
         }

         // Create a table to store customer values.
         DataTable CustomerTable = new DataTable("Customer");

         // Define the columns for the Customer table.
         CustomerTable.Columns.Add(
            new DataColumn("CustomerName", typeof(string)));
         CustomerTable.Columns.Add(
            new DataColumn("CustomerID", typeof(int)));

         // Populate the Customer table.
         for (int i=1; i<=5; i++) 
         {
            TempDataRow = CustomerTable.NewRow();
            TempDataRow[0] = "Customer " + i.ToString();
            TempDataRow[1] = (i+1700);

            CustomerTable.Rows.Add(TempDataRow);
         }

         // Create a DataSet and add the Employee and Customer tables.
         DataSet ds = new DataSet();
         ds.Tables.Add(EmployeeTable);
         ds.Tables.Add(CustomerTable);

         return ds;

      }
             
      void Page_Load(Object sender, EventArgs e) 
      {

         // The data source only needs to be bound to the DataList  
         // control the first time the page is accessed.    
         if(!IsPostBack)
         {

            // Create the sample data for the DataList control.
            ItemsGrid.DataSource = CreateDataSet();

            // The data source in this example contains multiple tables. 
            // Specify which table to display in the DataList control. 
            ItemsGrid.DataMember = "Customer";

            // Bind the data source to the control.
            ItemsGrid.DataBind();

         }

      }

      void Index_Change(Object sender, EventArgs e) 
      {

         // Create the sample data for the DataList control.
         ItemsGrid.DataSource = CreateDataSet();

         // The data source in this example contains multiple tables. 
         // Specify which table to display in the DataList control 
         // based on the user's selection from the DropDownList control. 
         ItemsGrid.DataMember = SourceList.SelectedItem.Text;

         // Bind the data source to the control. 
         ItemsGrid.DataBind();

      }

   </script>

</head>
<body>

   <form id="form1" runat="server">

      <h3> BaseDataList DataMember Example </h3>
      
      <asp:DataGrid id="ItemsGrid"
           AutoGenerateColumns="True" 
           runat="server">

         <headerstyle backcolor="#00aaaa"/>
</asp:DataGrid>

      <br /><br />

      Select the data source: <br />

      <asp:DropDownList id="SourceList"
           AutoPostBack="True"
           OnSelectedIndexChanged="Index_Change"
           runat="server">

         <asp:Listitem Selected="True">Customer</asp:Listitem>
         <asp:Listitem>Employee</asp:Listitem>

      </asp:DropDownList>

   </form>
 
</body>

</html>

プラットフォーム

Windows 98,Windows Server 2000 SP4,Windows CE,Windows Millennium Edition,Windows Mobile for Pocket PC,Windows Mobile for Smartphone,Windows Server 2003,Windows XP Media Center Edition,Windows XP Professional x64 Edition,Windows XP SP2,Windows XP Starter Edition

Microsoft .NET Framework 3.0 は Windows Vista,Microsoft Windows XP SP2,および Windows Server 2003 SP1 でサポートされています。

バージョン情報

.NET Framework

サポート対象 : 3.0,2.0,1.1,1.0

参照

関連項目

BaseDataList クラス
BaseDataList メンバ
System.Web.UI.WebControls 名前空間
DataSource