Generalized filtering with GridView and SqlDataSource

K

kevinpond

I have a Gridview displaying the results of a stored procedure. The
stored procedure is constantly changing so the columns displayed in the
data grid are constantly changing. I'd like to give users the ability
to filter by the value of any column. This is easily done using the
FilterExpression property of the DataSource. However, prior to
creating the filter expression, I need to know if the column they wish
to filter contains text or numerical values (basically do I surround
the value to filter for in quotes or not.) Is there any way to
determine the data type of the underlying data column?
Any help would be greatly appreciated.
 
E

Eliyahu Goldin

To get info on columns, you need to get the schema. With SqlDataSource you
can get to the schema if you first get to the datatable. This article
explains how you can get the datatable out of SqlDataSource:
http://msmvps.com/blogs/egoldin/archive/2006/12/27/how-to-get-datatable-out-of-sqldatasource.aspx

Once you have the datatable, its Columns collection will take you to the
column. Column.DataType property will tell your the type of the column. You
can apply filtering to the datatable rather that to the datasource. It will
save you a trip to the database. DataTable.Select can return a filtered
array of rows and you can databind the grid to this array.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
 

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,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top