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

Generalized filtering with GridView and SqlDataSource

P: n/a
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.

Jan 9 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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/arch...atasource.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
<ke*******@yahoo.comwrote in message
news:11**********************@11g2000cwr.googlegro ups.com...
>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.

Jan 9 '07 #2

P: n/a

Thanks for your quick answer! That helped.

Jan 10 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.