【问题标题】:how can i display a productlist in a listbox based on the category button i click on?如何根据我单击的类别按钮在列表框中显示产品列表?
【发布时间】:2018-01-08 09:54:23
【问题描述】:

我有一个带有按钮的菜单,每个按钮都有一个类别。在菜单旁边,我放置了一个列表框。此列表框链接到数据库中的产品列表。我希望每当我按下类别按钮时,链接到该类别(带有 categoryID)的产品都会显示在列表框中。

我使用以下代码在列表框中显示产品

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

【问题讨论】:

  • 你没有尝试使用 where 过滤产品from product in db.products where product.CategoryId = selectedCategoryId select product
  • 不起作用,product.categoryId 带有红色下划线
  • 不要只是复制粘贴代码。理解逻辑。您在产品对象中有什么属性来表示它的类别?
  • 我没有复制粘贴,但是 where 子句不起作用
  • 我的代码有一个小错误。更新的是from product in db.products where product.CategoryId == selectedCategoryId select product。试试这个。如果有错误,请在此处分享确切的错误。

标签: c# sql foreign-keys categories customer


【解决方案1】:
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;
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-06-25
    • 2019-07-07
    • 1970-01-01
    • 2021-12-07
    • 1970-01-01
    • 1970-01-01
    • 2018-06-14
    相关资源
    最近更新 更多