NatsuDragneel
NatsuDragneel

Reputation: 317

Search filename by textbox in asp.net

Is it possible to use textbox jquery as a searchbox to search a specific file and populate it on a treeview, gridview or listview? Like for example there's a filename currency ratings when I search currency it will search a file that has a word currency in it.

Tried this so far but listbox won't populate

        protected void Button1_Click(object sender, EventArgs e)
    {
        DirectoryInfo folder = new DirectoryInfo(Server.MapPath("~/files"));
        foreach (FileInfo files in folder.GetFiles(TextBox1.Text + ".jpg", SearchOption.AllDirectories))
        {
            ListBox1.Items.Add(files.Name);
        }
    }

Upvotes: 0

Views: 513

Answers (1)

emmet
emmet

Reputation: 67

Try this function

$('#box').keyup(function(){
   var valThis = $(this).val();
    $('.navList>li').each(function(){
     var text = $(this).text().toLowerCase();
        (text.indexOf(valThis) == 0) ? $(this).show() : $(this).hide();         
   });
});

Your textbox should have the id "box". Then, on the textbox's keypress, just simply call a class that would call the data based on the textbox's text. Sample query:

SELECT filename FROM files WHERE filename like '%search%'

Upon retrieving the file names from the db, just set your dataview.datasource to the search result.

Upvotes: 1

Related Questions