数据绑定到ADO.NET
// De?ne a DataSet with a single DataTable. DataSet dsInternal = new DataSet(); dsInternal.Tables.Add("Users"); // De?ne two columns for this table. dsInternal.Tables["Users"].Columns.Add("Name"); dsInternal.Tables["Users"].Columns.Add("Country"); // Add some actual information into the table. DataRow rowNew = dsInternal.Tables["Users"].NewRow(); rowNew["Name"] = "John"; rowNew["Country"] = "Uganda"; dsInternal.Tables["Users"].Rows.Add(rowNew); rowNew = dsInternal.Tables["Users"].NewRow(); rowNew["Name"] = "Samantha"; rowNew["Country"] = "Belgium"; dsInternal.Tables["Users"].Rows.Add(rowNew); rowNew = dsInternal.Tables["Users"].NewRow(); rowNew["Name"] = "Rico"; rowNew["Country"] = "Japan"; dsInternal.Tables["Users"].Rows.Add(rowNew); // De?ne the binding. lstUser.DataSource = dsInternal.Tables["Users"]; lstUser.DataTextField = "Name"; //或者 // De?ne the binding. lstUser.DataSource = dsInternal; lstUser.DataMember = "Users"; lstUser.DataTextField = "Name"; // this.DataBind();
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。