private void PopulateProductDropDown() { // Get the data from the BLL var controller = new ProductController(); var data = controller.ListProducts(); // Use the data in the DropDownList control CurrentProducts.DataSource = data; // supplies all the data to the control CurrentProducts.DataTextField = nameof(Product.ProductName); // identify which property will be used to display text CurrentProducts.DataValueField = nameof(Product.ProductID); // identify which property will be associated with the value of the <option> element CurrentProducts.DataBind(); // Insert an item at the top to be our "placeholder" for the <select> tag CurrentProducts.Items.Insert(0, "[select a product]"); }
private void PopulateProductsDropDown() { // We can populate some controls such as DropDownLists with data // Populate CurrentProducts with all the products in the database InventoryPurchasingController controller = new InventoryPurchasingController(); // controller is a NorthwindController object List <Product> products = controller.ListAllProducts(); // products is a List<Product> object CurrentProducts.DataSource = products; // CurrentProducts is a DropDownList CurrentProducts.DataTextField = "ProductName"; // The property of the Product class to display CurrentProducts.DataValueField = "ProductID"; CurrentProducts.DataBind(); // Populate the DropDownList CurrentProducts.Items.Insert(0, "[select a product]"); }