Search code examples
c#sqlforeign-keyscategories

how can i display a productlist in a listbox based on the category button i click on?


I have a menu with buttons, each button has a category on it. Next to the menu i placed a listbox. This listbox is linked to a productlist in the database. I want that whenever I press a categorybutton, the products linked to that category (with a categoryID) will display in the listbox.

Im using the following code to display the products in the listbox

var productslist = from products in db.products select products;
prodlb.ItemsSource = productslist;

Solution

  • private void Buttonproducts_OnClick(object sender, RoutedEventArgs e)
        {
            var productslist = from products in db.products select products;
            prodlb.ItemsSource = productslist;
        }
    
    private void ButtonCustomers_OnClick(object sender, RoutedEventArgs e)
        {
            var Customerslist = from Customers in db.customers select customers;
            prodlb.ItemsSource = Customerslist;
        }