【问题标题】:How to search listbox using the same criteria as like "%%" in sql如何使用与 sql 中的“%%”相同的条件搜索列表框
【发布时间】:2013-02-12 21:57:11
【问题描述】:

如何使用与 sql 中的 "%%" 相同的条件搜索 ListBox 例如,如果列表包含以下项目 {cat , dog , cat with ring,dog with bone} 并在文本框中输入“with”。我需要过滤此列表框以仅包含包含单词“with”的记录(即 {cat with ring,dog with bone})。

到目前为止,我可以使用此代码搜索并选择以输入字符串开头的项目..

    private void txtSearch_TextChanged(object sender, EventArgs e)
    {
        int index = lst.FindString(this.txtSearch.Text);
        if (0 <= index)
        {
            lst.SelectedIndex = index;
        }
    }

【问题讨论】:

标签: c# sql-server


【解决方案1】:

应该这样做:

string searchTerm = this.txtSearch.Text;
var items = lst.Items.Cast<ListItem>().Where(t=>t.Value.Contains(searchTerm));

items 将包含所有具有包含您的搜索词的Value 的 ListItem。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-30
    • 2021-08-09
    相关资源
    最近更新 更多