0

Possible Duplicate:
How to highlight the results of a text in a gridview?

I've asked for many times..I got answers but I have no idea how to do it.. I have a textbox for searching a text inside a gridview table..but I don't know how to do it..please help me sql database 2008 , asp.net,c#

Community
  • 1
  • 1
John Mokien
  • 435
  • 4
  • 12

1 Answers1

0

You can user Dataview Rowfilter to repopulate your Gridview to search..

.....
.....
DataView dvData = new DataView(yourDataTableGoesHere);
dvData .RowFilter = "Name LIKE 'j*'" 
DGV.DataSource = dvData;
DGV.DataBind();

Using Jquery to highlight a datagridview when searched

 string SearchString = "";
    protected void Page_Load(object sender, EventArgs e)
    {
txtSearch.Attributes.Add("onkeyup", "setTimeout('__doPostBack(\'" + txtSearch.ClientID.Replace("_", "$") + "\',\'\')', 0);");
        if (!IsPostBack)
        {
            Gridview1.DataBind();
        }
    }
    protected void txtSearch_TextChanged(object sender, EventArgs e)
    {
         SearchString = txtSearch.Text;
    }
    public string HighlightText(string InputTxt)
    {
        string Search_Str = txtSearch.Text.ToString();
        // Setup the regular expression and add the Or operator.
        Regex RegExp = new Regex(Search_Str.Replace(" ", "|").Trim(), RegexOptions.IgnoreCase);
        // Highlight keywords by calling the
        //delegate each time a keyword is found.
        return RegExp.Replace(InputTxt, new MatchEvaluator(ReplaceKeyWords));
        // Set the RegExp to null.
        RegExp = null;
    }
    public string ReplaceKeyWords(Match m)
    {
        return "<span class=highlight>" + m.Value + "</span>";
    }

reference

Rizwan Mumtaz
  • 3,875
  • 2
  • 30
  • 31