This documentation is archived and is not being maintained.

DataMember Property

.NET Framework 1.1

Sets or returns the data member to extract when data binding to a list data source. The default value is an empty string ("").

public virtual string DataMember {
   get,
   set
}

Remarks

This property is only used if the value of the DataSource property is of type IListSource, rather than of type IEnumerable.

Example

The following example demonstrates how to use the DataMember property to associate the table to the data source.

Dim dataSet1 As New DataSet()
Dim sqlDataAdapter1 As New SqlDataAdapter()
Dim sqlSelectCommand1 As New SqlCommand()
Dim sqlConnection1 As New SqlConnection()

'Set the variables.
sqlSelectCommand1.CommandText = "...SQL Query.." '
sqlSelectCommand1.Connection = sqlConnection1
sqlConnection1.ConnectionString = "data source=Server Name;" + "initial catalog=DB Name ;persist security info=False;" + "Integrated Security=SSPI"
sqlDataAdapter1.SelectCommand = Me.sqlSelectCommand1

' Fill the data set with the result of the query.
' The results are stored in the data set called "Table1".
sqlDataAdapter1.Fill(dataSet1, "Table1")
ObjectList1.LabelField = "status"
ObjectList1.DataSource = dataSet1
' A data set can have more then one table in it's TablesCollection.
ObjectList1.DataMember = "Table1"
ObjectList1.DataBind()

[C#]
public void Page_Load(Object sender, EventArgs e)
{
   DataSet dataSet1 = new DataSet();
   SqlDataAdapter sqlDataAdapter1 = new SqlDataAdapter();
   SqlCommand sqlSelectCommand1   = new SqlCommand();
   SqlConnection sqlConnection1   = new SqlConnection();
 
   //Set the variables.
   sqlSelectCommand1.CommandText   = @"...SQL Query..";
   sqlSelectCommand1.Connection    = sqlConnection1;
   sqlConnection1.ConnectionString = "data source=Server Name;"
      + "initial catalog=DB Name ;persist security info=False;"
      + "Integrated Security=SSPI";
   sqlDataAdapter1.SelectCommand = this.sqlSelectCommand1;

   // Fill the data set with the result of the query.
   // The results are stored in the data set called "Table1".
   sqlDataAdapter1.Fill(dataSet1,"Table1");
   ObjectList1.LabelField = "status";
   ObjectList1.DataSource = dataSet1;
   // A data set can have more then one table in it's TablesCollection.
   ObjectList1.DataMember = "Table1";
   ObjectList1.DataBind();
}

See Also

Applies to: List Class | ObjectList Class | SelectionList Class

Show: