Asp.net C# 突出显示来自文本框多个单词的匹配 Gridview 标签文本
Asp.net C# Highlight matching Gridview label text from textbox multiple words
当在文本框中输入值时,应突出显示与 GridView 的内容匹配的值。我可以用一个单词实现这一点,但是当我在文本框中使用多个单词时,它就不起作用了。任何帮助将非常感激。下面是我的 C# 代码:
foreach (GridViewRow gvr in GridView1.Rows) //loop each row
{
Label lblDescription = gvr.FindControl("lblDescription") as Label;
lblDescription.Text = Regex.Replace(lblDescription.Text, txtSearch.Text.Trim(), delegate (Match match)
{
return string.Format("<span style = 'background-color:#f30a31'>{0}</span>", match.Value);
}, RegexOptions.IgnoreCase);
}
foreach (GridViewRow gvr in GridView1.Rows) //loop each row
{
Label lblDescription = gvr.FindControl("lblDescription") as Label;
string searchtext = txtSearch.Text;
string[] searchtextList = searchtext.Split(' ');
foreach (string textlist in searchtextList)
{
lblDescription.Text = Regex.Replace(lblDescription.Text, textlist.Trim(), delegate (Match match)
{
return string.Format("<span style = 'background-color:#ee953f'>{0}</span>", match.Value);
}, RegexOptions.IgnoreCase);
}
}
当在文本框中输入值时,应突出显示与 GridView 的内容匹配的值。我可以用一个单词实现这一点,但是当我在文本框中使用多个单词时,它就不起作用了。任何帮助将非常感激。下面是我的 C# 代码:
foreach (GridViewRow gvr in GridView1.Rows) //loop each row
{
Label lblDescription = gvr.FindControl("lblDescription") as Label;
lblDescription.Text = Regex.Replace(lblDescription.Text, txtSearch.Text.Trim(), delegate (Match match)
{
return string.Format("<span style = 'background-color:#f30a31'>{0}</span>", match.Value);
}, RegexOptions.IgnoreCase);
}
foreach (GridViewRow gvr in GridView1.Rows) //loop each row
{
Label lblDescription = gvr.FindControl("lblDescription") as Label;
string searchtext = txtSearch.Text;
string[] searchtextList = searchtext.Split(' ');
foreach (string textlist in searchtextList)
{
lblDescription.Text = Regex.Replace(lblDescription.Text, textlist.Trim(), delegate (Match match)
{
return string.Format("<span style = 'background-color:#ee953f'>{0}</span>", match.Value);
}, RegexOptions.IgnoreCase);
}
}