I already have the datatable. I just need to fill it in the list view. The problem is that I’m running into this error:
‘System.Web.UI.WebControls.ListView’ does not contain a definition for ‘DisplayMember’ and no extension method ‘DisplayMember’ accepting a first argument of type ‘System.Web.UI.WebControls.ListView’ could be found (are you missing a using directive or an assembly reference?)
I thought the list view had a “DisplayMember” property? This is ASP .NET 4.0, by the way.
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;
}
}
}
}
}
}
}
This should work: