【问题标题】:How to filter ListBox using Check box list如何使用复选框列表过滤 ListBox
【发布时间】:2015-05-21 15:39:11
【问题描述】:

我在 asp.net 网络表单中有复选框列表和列表框, 复选框列表设置为从 N 表中获取其数据源, ListBox 设置为从 P 表中获取其数据源, p 和 N 表之间存在多对多关系,所以有一个表 P_N 现在我想检查一个或多个复选框,结果列表框中的 P 被过滤,N 表由(N_Id,N_Name)组成,P 表由(P_ID,P_Name)组成 和 P_N 表由 (P_ID, N_ID) 组成

【问题讨论】:

    标签: c# asp.net listbox checkboxlist


    【解决方案1】:

    您将遍历您的 CheckBox 列表以获取要显示的结果...

    var results;
    
    foreach (var i in CheckBoxList.Items)
    {
        if (i.Checked == true)
        { // Add selected ID to ListBox
            results += (from c in PTable.All()
                        where c.ID == i.Value // i.Value would be however you're storing the ID in the CheckBoxList
                        select c).ToList();
        }
    }
    
    ListBox.DataSource = results;
    ListBox.DataBind();
    

    当然是伪代码,但它应该可以帮助您入门。

    【讨论】:

      猜你喜欢
      • 2015-05-13
      • 2012-06-12
      • 2017-03-19
      • 1970-01-01
      • 2021-10-30
      • 1970-01-01
      • 1970-01-01
      • 2019-04-01
      • 2014-03-08
      相关资源
      最近更新 更多