【问题标题】:how to data dynamic search in C# and search is perform using textbox key event如何在 C# 中进行数据动态搜索并使用文本框键事件执行搜索
【发布时间】:2017-09-16 16:16:52
【问题描述】:

我有 1 个文本框和 1 个网格,我想使用文本框使用按键事件搜索动态数据,并在网格中突出显示我要搜索的那个词。

【问题讨论】:

标签: c# asp.net


【解决方案1】:

OnKeyPress 事件附加到您的 TextBox 并在该事件中编写您的逻辑。

private void TextBox_KeyPress(object sender, KeyPressEventArgs e)        
{
    string value = TextBox.Text;
    foreach(GridViewRow row in GridView.Rows)
    {
        for(int i = 0; i < GridView.Columns.Count; i++)
        {
            string cellText = row.Cells[i].Text;
            if(cellText == value)
            {
                // Highlights the entire row
                row.DefaultCellStyle.SelectionBackColor = Color.Yellow;
                break;
            }
        }
    }
}

【讨论】:

    猜你喜欢
    • 2011-07-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-04
    • 2018-03-01
    相关资源
    最近更新 更多