By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,206 Members | 998 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,206 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Nov 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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" <da*******@yahoo.com> wrote in message news:ux**************@TK2MSFTNGP09.phx.gbl... 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

Nov 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.