Josh Jeffers
Josh Jeffers

Reputation: 25

Create a Search Bar with a Text box for a datagrid Visual Basic

I am using Visual Basic 2010 and am trying to create a datagrid where I can view data from my Sql Server database.

I have the datagrid setup and importing the data from SQL Server, but I am now trying to create on the form something where the user can type into a text box a value, and select a column header from a drop box to pull up a the desired rows.

So I want to be able to type into the Text Box "John" and select in the drop box "Names"

and this would pull up all rows with "John" in column "Names"

Seems simple, but so far I've built everything in the form with just drag and drop from the toolbox so I'm having trouble understanding where to type in backend code for something like this.

Any advice for how this should be approached, or even where I should put code for this would be helpful.

Thank you!

Upvotes: 0

Views: 4180

Answers (2)

Sanjay Goswami
Sanjay Goswami

Reputation: 1386

Try below code on search button click

DataTable dt = GetData();
            if (ds.SelectedIndex != -1 && txtFieldValue.Text != "")
            {
                string search = ds.SelectedItem.Text + "=" + txtFieldValue.Text;
                dg.Datasource =  dt.Select(search);
                dg.Databind();
            }

Upvotes: 1

Mulesoft Developer
Mulesoft Developer

Reputation: 2824

You need to use keyup event with jquery/javascript and update data there is no other way to update data with out any event.

Upvotes: 0

Related Questions