Esempio n. 1
0
    private void PopulateSupplierDropDown()
    {
        InventoryPurchasingController controller = new InventoryPurchasingController();
        List <Supplier> data = controller.ListAllSuppliers();

        SupplierDropDown.DataSource     = data;
        SupplierDropDown.DataTextField  = "CompanyName";
        SupplierDropDown.DataValueField = "SupplierID";
        SupplierDropDown.DataBind();
        SupplierDropDown.Items.Insert(0, "[select a supplier]");
    }
        private void PopulateSupplierDropDown()
        {
            var             controller = new SupplierController();
            List <Supplier> suppliers  = controller.ListSuppliers();

            SupplierDropDown.DataSource     = suppliers;
            SupplierDropDown.DataTextField  = nameof(Supplier.CompanyName);
            SupplierDropDown.DataValueField = nameof(Supplier.SupplierID);
            SupplierDropDown.DataBind();
            // Let's insert a couple of options at the top of the drop-down
            SupplierDropDown.Items.Insert(0, new ListItem("[select a supplier]"));
            SupplierDropDown.Items.Insert(1, new ListItem("[no supplier]", string.Empty)); // because Product.SupplierID is nullable
        }
        private void BindSupplierDropDown()
        {
            SupplierController controller = new SupplierController();

            // SupplieDropDown is an object of type DropDownList
            // The .DataSource property takes any enumerable list of data
            SupplierDropDown.DataSource = controller.ListSuppliers();
            // The .DataTextField property specifies what property name should be called to get the data to display for the drop-down
            SupplierDropDown.DataTextField  = nameof(Supplier.CompanyName);
            SupplierDropDown.DataValueField = nameof(Supplier.SupplierID);
            SupplierDropDown.DataBind();
            SupplierDropDown.Items.Insert(0, new ListItem("[Select a supplier]", "-1"));
        }
        private void BindSupplierDropDown()
        {
            SupplierController controller = new SupplierController();

            //Supplier drop down is an object of type drop down list. The datasource property takes any enumerable list of data
            SupplierDropDown.DataSource = controller.ListSuppliers();
            //Datatextfield specifies what property name should be called to get the data to display for the dropdown
            SupplierDropDown.DataTextField = nameof(Supplier.CompanyName);
            //Datavalue field property specified what propert yname should be called to get the data to use as the value for the drop down options
            SupplierDropDown.DataValueField = nameof(Supplier.SupplierID);
            //Populate the drop-down by taking the data and "Unpacking" it
            SupplierDropDown.DataBind();
            //Insert an item into index[0] for the frop down list
            SupplierDropDown.Items.Insert(0, new ListItem("[Select a supplier]", "-1"));
        }