HtmlSelect.DataMember プロパティ
アセンブリ: System.Web (system.web.dll 内)

Dim instance As HtmlSelect Dim value As String value = instance.DataMember instance.DataMember = value
/** @property */ public String get_DataMember () /** @property */ public void set_DataMember (String value)
複数のデータ セットを持つ DataSource から HtmlSelect コントロールにバインドするデータ セット。既定値は空の文字列 ("") です。このプロパティが設定されていないことを示します。

DataSource プロパティに複数のデータ セットが格納されている場合は、DataMember プロパティを使用して、コントロールにバインドするデータ セットを指定します。たとえば、複数のテーブルの System.Data.DataSet オブジェクトがある場合は、このプロパティを使用してどのテーブルをコントロールにバインドするかを指定します。
コントロールにバインドするデータ ソースを指定した後は、データ ソースのどのフィールドをコントロールの各項目の ListItem.Text プロパティと ListItem.Value プロパティにバインドするかを DataTextField プロパティと DataValueField プロパティを個別に設定することで指定できます。

DataMember プロパティを使用して、複数のデータ セットを持つ DataSource プロパティから HtmlSelect コントロールにバインドするデータ セットを指定する方法を次のコード例に示します。
<%@ Page Language="VB" AutoEventWireup="True" %> <%@ Import Namespace="System.Data" %> <html> <head> <script runat="server"> Sub Page_Load (sender As Object, e As EventArgs) ' Bind the HtmlSelect control to a data source when the page is initially loaded. If Not IsPostBack Then Dim i As Integer ' Create a data set to store the tables. Dim ds As DataSet = New DataSet("TitleDataSet") Dim dr As DataRow ' Create the authors table with a single column. Dim authors As DataTable = New DataTable("Authors") authors.Columns.Add(New DataColumn("LName", GetType(String))) ' Add the authors table to the data set. ds.Tables.Add(authors) ' Create sample data in the authors table. For i = 0 To 9 ' Create a new row for the authors table. dr = authors.NewRow() ' Add data to the LName column (column 0 in the row). dr(0) = "Author " & i.ToString() ' Insert the row into the authors table. authors.Rows.Add(dr) Next i ' Create the titles table with a single column. Dim titles As DataTable = New DataTable("Titles") titles.Columns.Add(New DataColumn("BookTitle", GetType(String))) ' Add the titles table to the data set. ds.Tables.Add(titles) ' Create sample data in the titles table. For i = 0 To 9 ' Create a new row for the titles table. dr = titles.NewRow() ' Add data to the BookTitle column (column 0 in the row). dr(0) = "Title " & i.ToString() ' Insert the row into the titles table. titles.Rows.Add(dr) Next i ' Bind the HtmlSelect control to the data source. Select1.DataSource = ds Select1.DataMember = "Titles" Select1.DataTextField = "BookTitle" Select1.DataBind() End If End Sub Sub Button_Click (sender As Object, e As EventArgs) Dim i As Integer ' Display the selected items. Label1.Text = "You selected:" For i=0 To Select1.Items.Count - 1 If Select1.Items(i).Selected Then Label1.Text = Label1.Text & "<br> - " & Select1.Items(i).Text End If Next i End Sub </script> </head> <body> <form runat="server"> <h3> HtmlSelect Example </h3> Select items from the list. <br> Use the Control or Shift key to select multiple items. <br><br> <select id="Select1" Multiple="True" runat="server"/> <br><br> <button id="Button1" OnServerClick="Button_Click" runat="server"> Submit </button> <br><br> <asp:Label id="Label1" runat="server"/> </form> </body> </html>
<%@ Page Language="C#" AutoEventWireup="True" %> <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.SqlClient" %> <html> <head> <script runat="server"> void Page_Load (Object sender, EventArgs e) { // Bind the HtmlSelect control to a data source when the page is initially loaded. if (!IsPostBack) { // Create a data set to store the tables. DataSet ds = new DataSet("TitleDataSet"); DataRow dr; // Create the authors table with a single column. DataTable authors = new DataTable("Authors"); authors.Columns.Add(new DataColumn("LName", typeof(string))); // Add the authors table to the data set. ds.Tables.Add(authors); // Create sample data in the authors table. for (int i = 0; i < 9; i++) { // Create a new row for the authors table. dr = authors.NewRow(); // Add data to the LName column (column 0 in the row). dr[0] = "Author " + i.ToString(); // Insert the row into the authors table. authors.Rows.Add(dr); } // Create the titles table with a single column. DataTable titles = new DataTable("Titles"); titles.Columns.Add(new DataColumn("BookTitle", typeof(string))); // Add the titles table to the data set. ds.Tables.Add(titles); // Create sample data in the titles table. for (int i = 0; i < 9; i++) { // Create a new row for the titles table. dr = titles.NewRow(); // Add data to the BookTitle column (column 0 in the row). dr[0] = "Title " + i.ToString(); // Insert the row into the titles table. titles.Rows.Add(dr); } // Bind the HtmlSelect control to the data source. Select1.DataSource = ds; Select1.DataMember = "Titles"; Select1.DataTextField = "BookTitle"; Select1.DataBind(); } } void Button_Click (Object sender, EventArgs e) { // Display the selected items. Label1.Text = "You selected:"; for (int i=0; i<=Select1.Items.Count - 1; i++) { if (Select1.Items[i].Selected) Label1.Text += "<br> - " + Select1.Items[i].Text; } } </script> </head> <body> <form runat="server"> <h3> HtmlSelect Example </h3> Select items from the list. <br> Use the Control or Shift key to select multiple items. <br><br> <select id="Select1" Multiple="True" runat="server"/> <br><br> <button id="Button1" OnServerClick="Button_Click" runat="server"> Submit </button> <br><br> <asp:Label id="Label1" runat="server"/> </form> </body> </html>
<%@ Page Language="JScript" AutoEventWireup="True" %> <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.SqlClient" %> <html> <head> <script runat="server"> function Page_Load (sender : Object, e : EventArgs) { // Bind the HtmlSelect control to a data source when the page is initially loaded. if (!IsPostBack) { // Create a data set to store the tables. var ds : DataSet = new DataSet("TitleDataSet"); var dr : DataRow; // Create the authors table with a single column. var authors : DataTable = new DataTable("Authors"); authors.Columns.Add(new DataColumn("LName", GetType("String"))); // Add the authors table to the data set. ds.Tables.Add(authors); // Create sample data in the authors table. for (var i : int = 0; i < 9; i++) { // Create a new row for the authors table. dr = authors.NewRow(); // Add data to the LName column (column 0 in the row). dr[0] = "Author " + i.ToString(); // Insert the row into the authors table. authors.Rows.Add(dr); } // Create the titles table with a single column. var titles : DataTable = new DataTable("Titles"); titles.Columns.Add(new DataColumn("BookTitle", GetType("String"))); // Add the titles table to the data set. ds.Tables.Add(titles); // Create sample data in the titles table. for (var j : int = 0; j < 9; j++) { // Create a new row for the titles table. dr = titles.NewRow(); // Add data to the BookTitle column (column 0 in the row). dr[0] = "Title " + j.ToString(); // Insert the row into the titles table. titles.Rows.Add(dr); } // Bind the HtmlSelect control to the data source. Select1.DataSource = ds; Select1.DataMember = "Titles"; Select1.DataTextField = "BookTitle"; Select1.DataBind(); } } function Button_Click (sender : Object, e : EventArgs) { // Display the selected items. Label1.Text = "You selected:"; for (var i : int = 0; i <= Select1.Items.Count - 1; i++) { if (Select1.Items[i].Selected) Label1.Text += "<br> - " + Select1.Items[i].Text; } } </script> </head> <body> <form runat="server"> <h3> HtmlSelect Example </h3> Select items from the list. <br> Use the Control or Shift key to select multiple items. <br><br> <select id="Select1" Multiple="True" runat="server"/> <br><br> <button id="Button1" OnServerClick="Button_Click" runat="server"> Submit </button> <br><br> <asp:Label id="Label1" runat="server"/> </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
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からHtmlSelect.DataMember プロパティを検索する場合は、下記のリンクをクリックしてください。

- HtmlSelect.DataMember プロパティのページへのリンク