954,157 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

highlighting search results in a gridview problem

hi, i have a gridview search which filters the gridview, displaying the search results, however it wont highlight the results in yellow:

//Highlight relevant search results
        public string Highlight()
        {
            //Declaring a variable to hold search query
            string s = txtSearch.Text;

            if (s != null)
            {
                //string Search_Str = txtGrid.Text.ToString();  

                // Setup the regular expression    
                Regex RegExp = new Regex(s.Replace(" ", "|").Trim(), RegexOptions.IgnoreCase);

                //Highlight keywords by calling the delegate         
                //each time a keyword is found.        
                return
                   RegExp.Replace(s, new MatchEvaluator(ReplaceKeyWords));
                // Set the RegExp to null.            
                //RegExp = null;        
            }
            else
            {
                return s;
            }
        }


        // Method which helps find and highlight search results
        public string ReplaceKeyWords(Match m)
        {

            return "<span class=highlight>" + m.Value + "</span>";
        }


can any1 see a problem?
cheers

julseypart
Light Poster
42 posts since Oct 2008
Reputation Points: 10
Solved Threads: 0
 
mail2saion
Posting Whiz in Training
247 posts since Apr 2009
Reputation Points: 26
Solved Threads: 44
 

if i enter manoj sagoi than it should highlight manoj sagoi,only .currently it's highlighting all manoj inside a paragraph.

hi, i have a gridview search which filters the gridview, displaying the search results, however it wont highlight the results in yellow:

//Highlight relevant search results
        public string Highlight()
        {
            //Declaring a variable to hold search query
            string s = txtSearch.Text;

            if (s != null)
            {
                //string Search_Str = txtGrid.Text.ToString();  

                // Setup the regular expression    
                Regex RegExp = new Regex(s.Replace(" ", "|").Trim(), RegexOptions.IgnoreCase);

                //Highlight keywords by calling the delegate         
                //each time a keyword is found.        
                return
                   RegExp.Replace(s, new MatchEvaluator(ReplaceKeyWords));
                // Set the RegExp to null.            
                //RegExp = null;        
            }
            else
            {
                return s;
            }
        }


        // Method which helps find and highlight search results
        public string ReplaceKeyWords(Match m)
        {

            return "<span class=highlight>" + m.Value + "</span>";
        }

can any1 see a problem? cheers

manoj.sagoi@gma
Newbie Poster
1 post since Feb 2010
Reputation Points: 10
Solved Threads: 0
 

Welcome manoj.sagoi@gma.

If you want to ask question, start your own thread.

__avd
Posting Genius (adatapost)
Moderator
8,647 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You