![](/img/trans.png)
[英]Setting label text in DataBinding in a GridView (ASP.NET/C#)
[英]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);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.