Easy one - How do I filter a datagrid based on textbox value?

R

RockNRoll

I'm new to ASP.NET and need to filter a datagrid based on a textbox value.

I have a working datagrid and would like the WHERE part of my SQL statement
to call the value of a textbox and refresh the datagrid when a button is
clicked.

SELECT RateMatrix.Name, RateMatrix.[Labor Class], RateMatrix.EC,
RateMatrix.[TM Rate], RateMatrix.[Bus Unit] FROM RateMatrix WHERE
([RateMatrix].[TM Rate] <= TEXTBOX_VALUE_GOES_HERE)

Thanks,

-Dave
 
R

Raterus

Depending on the size of ALL the data you could possibly display, one option is to load all the data into a DataTable, and then create a DataView with a rowfilter set to filter out just the rows you want, then bind the view to the DataSet. You could then persist the data in the session so you don't need to go back to the database each time.

Or, and probably easiest is to modify your sql statement to use a parameter
SELECT RateMatrix.Name, RateMatrix.[Labor Class], RateMatrix.EC,
RateMatrix.[TM Rate], RateMatrix.[Bus Unit] FROM RateMatrix WHERE
([RateMatrix].[TM Rate] <= @search)

after you load this sql statement into a command object, add this
myCommand.parameters.add("@search", txtSearch.text)

either way would work

--Michael


RockNRoll said:
I'm new to ASP.NET and need to filter a datagrid based on a textbox value.

I have a working datagrid and would like the WHERE part of my SQL statement
to call the value of a textbox and refresh the datagrid when a button is
clicked.

SELECT RateMatrix.Name, RateMatrix.[Labor Class], RateMatrix.EC,
RateMatrix.[TM Rate], RateMatrix.[Bus Unit] FROM RateMatrix WHERE
([RateMatrix].[TM Rate] <= TEXTBOX_VALUE_GOES_HERE)

Thanks,

-Dave
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,128
Latest member
ElwoodPhil
Top