Condividi tramite


Proprietà DataMember

Imposta o restituisce il membro dati da estrarre durante l'associazione di dati a un'origine dati elenco. Il valore predefinito è una stringa vuota ("").

public virtual string DataMember {
   get,
   set
}

Osservazioni

La proprietà viene utilizzata soltanto se il valore della proprietà DataSource è del tipo IlistSource e non del tipo IEnumerable.

Esempio

Nell'esempio che segue viene illustrato come utilizzare la proprietà DataMember per associare la tabella all'origine dati.

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();
}

Vedere anche

Si applica a: classe List | Classe ObjectList | Classe SelectionList