我已经有了数据表。我只需要在列表视图中填写它。问题是我遇到了这个错误:
“System.Web.UI.WebControls.ListView”不包含“DisplayMember”的定义,并且找不到接受“System.Web.UI.WebControls.ListView”类型的第一个参数的扩展方法“DisplayMember”(你是缺少 using 指令或程序集引用?)
我认为列表视图有一个“DisplayMember”属性?顺便说一下,这是 ASP .NET 4.0。
namespace Eagle_Replication_Manager
{
public partial class wfrmMain : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//on page load, I want to get a database table and populate this list view:
lvItems.DataSource = GetSourceDBs();
//This does not work, error here:
lvItems.DisplayMember = "Description";
}
private DataTable GetSourceDBs()
{
using (SqlConnection conn = new SqlConnection(AppVars.connectionString))
{
using (SqlCommand cmd = new SqlCommand("SELECT [Description] FROM [Warehouse].[dbo].[Items]", conn))
{
conn.Open();
cmd.ExecuteNonQuery();
using (SqlDataAdapter da = new SqlDataAdapter(cmd))
{
using (DataTable dt = new DataTable())
{
da.Fill(dt);
return dt;
}
}
}
}
}
}
}