471,595 Members | 1,594 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,595 software developers and data experts.

Generalized filtering with GridView and SqlDataSource

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
2 2119
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

Thanks for your quick answer! That helped.

Jan 10 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Bill Manring | last post: by
reply views Thread by Mike P | last post: by
reply views Thread by kurt.craver | last post: by
4 posts views Thread by =?Utf-8?B?QmFyYmFyYSBBbGRlcnRvbg==?= | last post: by
reply views Thread by Anwar ali | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.