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

Filtering data inside the Gridview Control?

P: n/a
Hello,

Does anyone have an idea on how I can filter the data in the gridview
control that was returned by an sql query?

I have a gridview that works fine when I populate it with data. Now I want
to look at that data and filter it based on what is in it.

I know that this could have been done with data sets and data views in
asp.net 1.1 but how is this done now in asp.net 2.0?

Is there a way to do this?

Thanks,

J
Dec 15 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Hi J,

Welcome to ASPNET newsgroup.
As for the filtering data displayed in the asp.net GridView control
question, based on my understanding, we should do this at DataSource
level... I think you're using a SqlDataSource to provide the data records
to the GridView , yes? If so, you can have alook at the following msdn
reference about using filtering function of the SqlDataSource....:

#How to: Enable Filtering for SqlDataSource Controls (Visual Studio)
http://msdn2.microsoft.com/en-us/library/ms178306.aspx

e.g:

<asp:CheckBox ID="Discontinued" runat="server" AutoPostBack="True" />
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$
ConnectionStrings:LocalNorthWind %>"
SelectCommand="SELECT [ProductID], [ProductName],
[Discontinued], [ReorderLevel], [CategoryID] FROM [Products]"
FilterExpression="Discontinued = {0}"
OnSelected="SqlDataSource1_Selected">
<FilterParameters>
<asp:ControlParameter ControlID="Discontinued"
Type="boolean"
Name="disc" PropertyName="Checked" />
</FilterParameters>
</asp:SqlDataSource>
The above sql datasource setting the filter as "Discontinued = {0}" , and
the parameter is defined in the <Filterparameters> collection... The
filter experssion is just the same as the Filter Expression we set for
DataView class programmatically. And this filtering is done through the
DataSet returned by the DataSourceControl rather than filtering at database
level ( the "Where" statement
of the DataSoureControl is used to done database level filtering .....

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


--------------------
| Reply-To: <wa********@newsgroups.nospam>
| From: <wa********@newsgroups.nospam>
| Subject: Filtering data inside the Gridview Control?
| Date: Wed, 14 Dec 2005 19:25:24 -0800
| Lines: 18
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
| X-RFC2646: Format=Flowed; Original
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
| Message-ID: <e0*************@TK2MSFTNGP09.phx.gbl>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: ip-206.159.118.137.hdiss.net 206.159.118.137
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP09.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:365002
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Hello,
|
| Does anyone have an idea on how I can filter the data in the gridview
| control that was returned by an sql query?
|
| I have a gridview that works fine when I populate it with data. Now I
want
| to look at that data and filter it based on what is in it.
|
| I know that this could have been done with data sets and data views in
| asp.net 1.1 but how is this done now in asp.net 2.0?
|
| Is there a way to do this?
|
| Thanks,
|
| J
|
|
|

Dec 15 '05 #2

P: n/a
Steven,

Cool that helped me with filtering the rows but I have one other question.

How do I search through the gridview? Would I do this at the sqldatasource
level?

I figured that I sould search with the datatable.select but how do I access
the datatable of the sqldatasource?

Thanks for your help

J
"Steven Cheng[MSFT]" <st*****@online.microsoft.com> wrote in message
news:5w**************@TK2MSFTNGXA02.phx.gbl...
Hi J,

Welcome to ASPNET newsgroup.
As for the filtering data displayed in the asp.net GridView control
question, based on my understanding, we should do this at DataSource
level... I think you're using a SqlDataSource to provide the data records
to the GridView , yes? If so, you can have alook at the following msdn
reference about using filtering function of the SqlDataSource....:

#How to: Enable Filtering for SqlDataSource Controls (Visual Studio)
http://msdn2.microsoft.com/en-us/library/ms178306.aspx

e.g:

<asp:CheckBox ID="Discontinued" runat="server" AutoPostBack="True" />
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$
ConnectionStrings:LocalNorthWind %>"
SelectCommand="SELECT [ProductID], [ProductName],
[Discontinued], [ReorderLevel], [CategoryID] FROM [Products]"
FilterExpression="Discontinued = {0}"
OnSelected="SqlDataSource1_Selected">
<FilterParameters>
<asp:ControlParameter ControlID="Discontinued"
Type="boolean"
Name="disc" PropertyName="Checked" />
</FilterParameters>
</asp:SqlDataSource>
The above sql datasource setting the filter as "Discontinued = {0}" , and
the parameter is defined in the <Filterparameters> collection... The
filter experssion is just the same as the Filter Expression we set for
DataView class programmatically. And this filtering is done through the
DataSet returned by the DataSourceControl rather than filtering at
database
level ( the "Where" statement
of the DataSoureControl is used to done database level filtering .....

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


--------------------
| Reply-To: <wa********@newsgroups.nospam>
| From: <wa********@newsgroups.nospam>
| Subject: Filtering data inside the Gridview Control?
| Date: Wed, 14 Dec 2005 19:25:24 -0800
| Lines: 18
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
| X-RFC2646: Format=Flowed; Original
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
| Message-ID: <e0*************@TK2MSFTNGP09.phx.gbl>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: ip-206.159.118.137.hdiss.net 206.159.118.137
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP09.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:365002
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Hello,
|
| Does anyone have an idea on how I can filter the data in the gridview
| control that was returned by an sql query?
|
| I have a gridview that works fine when I populate it with data. Now I
want
| to look at that data and filter it based on what is in it.
|
| I know that this could have been done with data sets and data views in
| asp.net 1.1 but how is this done now in asp.net 2.0?
|
| Is there a way to do this?
|
| Thanks,
|
| J
|
|
|

Dec 15 '05 #3

P: n/a
Hi J,

Thanks for the response. For searching, I'm afraid we have to do it at
datasource level since the GridView dosn't maintain orginal data records
after databinding (only displaying databound data......). Also, the
DataSource control is mainly used to provide statically data retrieveing
and work with databound controls, so we can manually call its methods to
retrieve the Selected data, but can not affect the way DataBound control
use it (we can only apply some parameters ...... in it...)

So for your scenario, you can try manually call the SqlDataSource control's
Select method with proper parameters then the returned object is the
datasouce (by default it is a DataView since the DataSourceMode is set to
"DataSet" ). e.g:

DataView dv = SqlDataSource1.Select(DataSourceSelectArguments.Em pty) as
DataView;
Response.Write("<br>Returned: " + dv.Table.Select(.....) );

Also, for such scenario, it is prefered that you not use DataSourceControl,
just programmatically retrieve the DataSet/DataTable your self and stored
in Cache, so that you can reuse it for searching later ......

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
| Reply-To: <wa********@newsgroups.nospam>
| From: <wa********@newsgroups.nospam>
| References: <e0*************@TK2MSFTNGP09.phx.gbl>
<5w**************@TK2MSFTNGXA02.phx.gbl>
| Subject: Re: Filtering data inside the Gridview Control?
| Date: Thu, 15 Dec 2005 01:48:11 -0800
| Lines: 110
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
| X-RFC2646: Format=Flowed; Original
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
| Message-ID: <ep**************@TK2MSFTNGP10.phx.gbl>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: ip-206.159.118.137.hdiss.net 206.159.118.137
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP10.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:365043
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Steven,
|
| Cool that helped me with filtering the rows but I have one other question.
|
| How do I search through the gridview? Would I do this at the
sqldatasource
| level?
|
| I figured that I sould search with the datatable.select but how do I
access
| the datatable of the sqldatasource?
|
| Thanks for your help
|
| J
|
|
| "Steven Cheng[MSFT]" <st*****@online.microsoft.com> wrote in message
| news:5w**************@TK2MSFTNGXA02.phx.gbl...
| > Hi J,
| >
| > Welcome to ASPNET newsgroup.
| > As for the filtering data displayed in the asp.net GridView control
| > question, based on my understanding, we should do this at DataSource
| > level... I think you're using a SqlDataSource to provide the data
records
| > to the GridView , yes? If so, you can have alook at the following msdn
| > reference about using filtering function of the SqlDataSource....:
| >
| > #How to: Enable Filtering for SqlDataSource Controls (Visual Studio)
| > http://msdn2.microsoft.com/en-us/library/ms178306.aspx
| >
| > e.g:
| >
| > <asp:CheckBox ID="Discontinued" runat="server" AutoPostBack="True" />
| > <asp:SqlDataSource ID="SqlDataSource1" runat="server"
| > ConnectionString="<%$
| > ConnectionStrings:LocalNorthWind %>"
| > SelectCommand="SELECT [ProductID], [ProductName],
| > [Discontinued], [ReorderLevel], [CategoryID] FROM [Products]"
| > FilterExpression="Discontinued = {0}"
| > OnSelected="SqlDataSource1_Selected">
| > <FilterParameters>
| > <asp:ControlParameter ControlID="Discontinued"
| > Type="boolean"
| > Name="disc" PropertyName="Checked" />
| > </FilterParameters>
| > </asp:SqlDataSource>
| >
| >
| > The above sql datasource setting the filter as "Discontinued = {0}" ,
and
| > the parameter is defined in the <Filterparameters> collection... The
| > filter experssion is just the same as the Filter Expression we set for
| > DataView class programmatically. And this filtering is done through the
| > DataSet returned by the DataSourceControl rather than filtering at
| > database
| > level ( the "Where" statement
| > of the DataSoureControl is used to done database level filtering .....
| >
| > Thanks,
| >
| > Steven Cheng
| > Microsoft Online Support
| >
| > Get Secure! www.microsoft.com/security
| > (This posting is provided "AS IS", with no warranties, and confers no
| > rights.)
| >
| >
| >
| >
| > --------------------
| > | Reply-To: <wa********@newsgroups.nospam>
| > | From: <wa********@newsgroups.nospam>
| > | Subject: Filtering data inside the Gridview Control?
| > | Date: Wed, 14 Dec 2005 19:25:24 -0800
| > | Lines: 18
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
| > | X-RFC2646: Format=Flowed; Original
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
| > | Message-ID: <e0*************@TK2MSFTNGP09.phx.gbl>
| > | Newsgroups: microsoft.public.dotnet.framework.aspnet
| > | NNTP-Posting-Host: ip-206.159.118.137.hdiss.net 206.159.118.137
| > | Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP09.phx.gbl
| > | Xref: TK2MSFTNGXA02.phx.gbl
| > microsoft.public.dotnet.framework.aspnet:365002
| > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
| > |
| > | Hello,
| > |
| > | Does anyone have an idea on how I can filter the data in the gridview
| > | control that was returned by an sql query?
| > |
| > | I have a gridview that works fine when I populate it with data. Now I
| > want
| > | to look at that data and filter it based on what is in it.
| > |
| > | I know that this could have been done with data sets and data views in
| > | asp.net 1.1 but how is this done now in asp.net 2.0?
| > |
| > | Is there a way to do this?
| > |
| > | Thanks,
| > |
| > | J
| > |
| > |
| > |
| >
|
|
|

Dec 16 '05 #4

P: n/a
Steven,

I was told by someone that I should just loop through the gridview and get
the data that way. Is this incorrect?

The way that you explain makes sense. Is the select method expression just
like SQL scripts? Because what I really need is to be able to do something
like, "SELECT DISTINCT column FROM table WHERE column='column'". For the
column that I want the data from, there are going to be many of the same
values. All I want is to know what ones are there. Therefore I dont need
duplicates. So if there were:

[column1]
hat
car
car
house
hat
hat
hat
car

It would return back to me:

hat
car
house

I am then going to take these values and put them into a datalist control
that will display these as hyperlinks. Then when the user clicks on the
hyperlink I can use that value as criteria for doing an sql query to the DB
thus repopulating the gridview and repopulating the datalist that represent
the values to filter by based on what was returned by the last sql query to
the DB.

I hope that makes sense.

I will try what you suggested and let you know how it works.

Thanks,

J

"Steven Cheng[MSFT]" <st*****@online.microsoft.com> wrote in message
news:dU**************@TK2MSFTNGXA02.phx.gbl...
Hi J,

Thanks for the response. For searching, I'm afraid we have to do it at
datasource level since the GridView dosn't maintain orginal data records
after databinding (only displaying databound data......). Also, the
DataSource control is mainly used to provide statically data retrieveing
and work with databound controls, so we can manually call its methods to
retrieve the Selected data, but can not affect the way DataBound control
use it (we can only apply some parameters ...... in it...)

So for your scenario, you can try manually call the SqlDataSource
control's
Select method with proper parameters then the returned object is the
datasouce (by default it is a DataView since the DataSourceMode is set to
"DataSet" ). e.g:

DataView dv = SqlDataSource1.Select(DataSourceSelectArguments.Em pty) as
DataView;
Response.Write("<br>Returned: " + dv.Table.Select(.....) );

Also, for such scenario, it is prefered that you not use
DataSourceControl,
just programmatically retrieve the DataSet/DataTable your self and stored
in Cache, so that you can reuse it for searching later ......

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
| Reply-To: <wa********@newsgroups.nospam>
| From: <wa********@newsgroups.nospam>
| References: <e0*************@TK2MSFTNGP09.phx.gbl>
<5w**************@TK2MSFTNGXA02.phx.gbl>
| Subject: Re: Filtering data inside the Gridview Control?
| Date: Thu, 15 Dec 2005 01:48:11 -0800
| Lines: 110
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
| X-RFC2646: Format=Flowed; Original
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
| Message-ID: <ep**************@TK2MSFTNGP10.phx.gbl>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: ip-206.159.118.137.hdiss.net 206.159.118.137
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP10.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:365043
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Steven,
|
| Cool that helped me with filtering the rows but I have one other
question.
|
| How do I search through the gridview? Would I do this at the
sqldatasource
| level?
|
| I figured that I sould search with the datatable.select but how do I
access
| the datatable of the sqldatasource?
|
| Thanks for your help
|
| J
|
|
| "Steven Cheng[MSFT]" <st*****@online.microsoft.com> wrote in message
| news:5w**************@TK2MSFTNGXA02.phx.gbl...
| > Hi J,
| >
| > Welcome to ASPNET newsgroup.
| > As for the filtering data displayed in the asp.net GridView control
| > question, based on my understanding, we should do this at DataSource
| > level... I think you're using a SqlDataSource to provide the data
records
| > to the GridView , yes? If so, you can have alook at the following
msdn
| > reference about using filtering function of the SqlDataSource....:
| >
| > #How to: Enable Filtering for SqlDataSource Controls (Visual Studio)
| > http://msdn2.microsoft.com/en-us/library/ms178306.aspx
| >
| > e.g:
| >
| > <asp:CheckBox ID="Discontinued" runat="server" AutoPostBack="True" />
| > <asp:SqlDataSource ID="SqlDataSource1" runat="server"
| > ConnectionString="<%$
| > ConnectionStrings:LocalNorthWind %>"
| > SelectCommand="SELECT [ProductID], [ProductName],
| > [Discontinued], [ReorderLevel], [CategoryID] FROM [Products]"
| > FilterExpression="Discontinued = {0}"
| > OnSelected="SqlDataSource1_Selected">
| > <FilterParameters>
| > <asp:ControlParameter ControlID="Discontinued"
| > Type="boolean"
| > Name="disc" PropertyName="Checked" />
| > </FilterParameters>
| > </asp:SqlDataSource>
| >
| >
| > The above sql datasource setting the filter as "Discontinued = {0}" ,
and
| > the parameter is defined in the <Filterparameters> collection... The
| > filter experssion is just the same as the Filter Expression we set for
| > DataView class programmatically. And this filtering is done through
the
| > DataSet returned by the DataSourceControl rather than filtering at
| > database
| > level ( the "Where" statement
| > of the DataSoureControl is used to done database level filtering .....
| >
| > Thanks,
| >
| > Steven Cheng
| > Microsoft Online Support
| >
| > Get Secure! www.microsoft.com/security
| > (This posting is provided "AS IS", with no warranties, and confers no
| > rights.)
| >
| >
| >
| >
| > --------------------
| > | Reply-To: <wa********@newsgroups.nospam>
| > | From: <wa********@newsgroups.nospam>
| > | Subject: Filtering data inside the Gridview Control?
| > | Date: Wed, 14 Dec 2005 19:25:24 -0800
| > | Lines: 18
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
| > | X-RFC2646: Format=Flowed; Original
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
| > | Message-ID: <e0*************@TK2MSFTNGP09.phx.gbl>
| > | Newsgroups: microsoft.public.dotnet.framework.aspnet
| > | NNTP-Posting-Host: ip-206.159.118.137.hdiss.net 206.159.118.137
| > | Path:
TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP09.phx.gbl
| > | Xref: TK2MSFTNGXA02.phx.gbl
| > microsoft.public.dotnet.framework.aspnet:365002
| > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
| > |
| > | Hello,
| > |
| > | Does anyone have an idea on how I can filter the data in the
gridview
| > | control that was returned by an sql query?
| > |
| > | I have a gridview that works fine when I populate it with data. Now
I
| > want
| > | to look at that data and filter it based on what is in it.
| > |
| > | I know that this could have been done with data sets and data views
in
| > | asp.net 1.1 but how is this done now in asp.net 2.0?
| > |
| > | Is there a way to do this?
| > |
| > | Thanks,
| > |
| > | J
| > |
| > |
| > |
| >
|
|
|

Dec 18 '05 #5

P: n/a
Hi J,

Thanks for your response.
Of course manually loop the gridView and extract values from each row is
one possible appraoch, but that's not a good idea, either hard to code also
have poor performance....
As for the further question you mentioned, I think it's better that you
move that query into a separate new datasource object, so that we can cache
that query to improve performance(I think those query of DISTINCT values
should be cachable....). We can use the Select statement and Select
parameters to define parameter based query like:

=======================
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$
ConnectionStrings:LocalNorthWind %>"
SelectCommand="SELECT [Discontinued], [ProductID],
[ProductName], [UnitPrice] FROM [Products] WHERE ([Discontinued] =
@Discontinued)">
<SelectParameters>
<asp:Parameter DefaultValue="true" Name="Discontinued"
Type="Boolean" />
</SelectParameters>
</asp:SqlDataSource>
<asp:GridView ID="GridView2" runat="server"
AutoGenerateColumns="False" DataKeyNames="ProductID"
DataSourceID="SqlDataSource2">
<Columns>
<asp:CheckBoxField DataField="Discontinued"
HeaderText="Discontinued" SortExpression="Discontinued" />
<asp:BoundField DataField="ProductID"
HeaderText="ProductID" InsertVisible="False"
ReadOnly="True" SortExpression="ProductID" />
<asp:BoundField DataField="ProductName"
HeaderText="ProductName" SortExpression="ProductName" />
<asp:BoundField DataField="UnitPrice"
HeaderText="UnitPrice" SortExpression="UnitPrice" />
</Columns>
</asp:GridView>
======================

And we can also programmatically call the datasource.select method with the
certain parameter instances as I've mentioned in the former message....

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
| Reply-To: <wa********@newsgroups.nospam>
| From: <wa********@newsgroups.nospam>
| References: <e0*************@TK2MSFTNGP09.phx.gbl>
<5w**************@TK2MSFTNGXA02.phx.gbl>
<ep**************@TK2MSFTNGP10.phx.gbl>
<dU**************@TK2MSFTNGXA02.phx.gbl>
| Subject: Re: Filtering data inside the Gridview Control?
| Date: Sun, 18 Dec 2005 14:48:48 -0800
| Lines: 231
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
| X-RFC2646: Format=Flowed; Original
| Message-ID: <u$**************@TK2MSFTNGP09.phx.gbl>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: ip-206.159.118.137.hdiss.net 206.159.118.137
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP09.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:365606
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Steven,
|
| I was told by someone that I should just loop through the gridview and
get
| the data that way. Is this incorrect?
|
| The way that you explain makes sense. Is the select method expression
just
| like SQL scripts? Because what I really need is to be able to do
something
| like, "SELECT DISTINCT column FROM table WHERE column='column'". For the
| column that I want the data from, there are going to be many of the same
| values. All I want is to know what ones are there. Therefore I dont
need
| duplicates. So if there were:
|
| [column1]
| hat
| car
| car
| house
| hat
| hat
| hat
| car
|
| It would return back to me:
|
| hat
| car
| house
|
| I am then going to take these values and put them into a datalist control
| that will display these as hyperlinks. Then when the user clicks on the
| hyperlink I can use that value as criteria for doing an sql query to the
DB
| thus repopulating the gridview and repopulating the datalist that
represent
| the values to filter by based on what was returned by the last sql query
to
| the DB.
|
| I hope that makes sense.
|
| I will try what you suggested and let you know how it works.
|
| Thanks,
|
| J
|
|
|
|
|
| "Steven Cheng[MSFT]" <st*****@online.microsoft.com> wrote in message
| news:dU**************@TK2MSFTNGXA02.phx.gbl...
| > Hi J,
| >
| > Thanks for the response. For searching, I'm afraid we have to do it at
| > datasource level since the GridView dosn't maintain orginal data records
| > after databinding (only displaying databound data......). Also, the
| > DataSource control is mainly used to provide statically data retrieveing
| > and work with databound controls, so we can manually call its methods to
| > retrieve the Selected data, but can not affect the way DataBound control
| > use it (we can only apply some parameters ...... in it...)
| >
| > So for your scenario, you can try manually call the SqlDataSource
| > control's
| > Select method with proper parameters then the returned object is the
| > datasouce (by default it is a DataView since the DataSourceMode is set
to
| > "DataSet" ). e.g:
| >
| > DataView dv = SqlDataSource1.Select(DataSourceSelectArguments.Em pty) as
| > DataView;
| > Response.Write("<br>Returned: " + dv.Table.Select(.....) );
| >
| > Also, for such scenario, it is prefered that you not use
| > DataSourceControl,
| > just programmatically retrieve the DataSet/DataTable your self and
stored
| > in Cache, so that you can reuse it for searching later ......
| >
| > Thanks,
| >
| > Steven Cheng
| > Microsoft Online Support
| >
| > Get Secure! www.microsoft.com/security
| > (This posting is provided "AS IS", with no warranties, and confers no
| > rights.)
| >
| >
| >
| > --------------------
| > | Reply-To: <wa********@newsgroups.nospam>
| > | From: <wa********@newsgroups.nospam>
| > | References: <e0*************@TK2MSFTNGP09.phx.gbl>
| > <5w**************@TK2MSFTNGXA02.phx.gbl>
| > | Subject: Re: Filtering data inside the Gridview Control?
| > | Date: Thu, 15 Dec 2005 01:48:11 -0800
| > | Lines: 110
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
| > | X-RFC2646: Format=Flowed; Original
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
| > | Message-ID: <ep**************@TK2MSFTNGP10.phx.gbl>
| > | Newsgroups: microsoft.public.dotnet.framework.aspnet
| > | NNTP-Posting-Host: ip-206.159.118.137.hdiss.net 206.159.118.137
| > | Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP10.phx.gbl
| > | Xref: TK2MSFTNGXA02.phx.gbl
| > microsoft.public.dotnet.framework.aspnet:365043
| > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
| > |
| > | Steven,
| > |
| > | Cool that helped me with filtering the rows but I have one other
| > question.
| > |
| > | How do I search through the gridview? Would I do this at the
| > sqldatasource
| > | level?
| > |
| > | I figured that I sould search with the datatable.select but how do I
| > access
| > | the datatable of the sqldatasource?
| > |
| > | Thanks for your help
| > |
| > | J
| > |
| > |
| > | "Steven Cheng[MSFT]" <st*****@online.microsoft.com> wrote in message
| > | news:5w**************@TK2MSFTNGXA02.phx.gbl...
| > | > Hi J,
| > | >
| > | > Welcome to ASPNET newsgroup.
| > | > As for the filtering data displayed in the asp.net GridView control
| > | > question, based on my understanding, we should do this at DataSource
| > | > level... I think you're using a SqlDataSource to provide the data
| > records
| > | > to the GridView , yes? If so, you can have alook at the following
| > msdn
| > | > reference about using filtering function of the SqlDataSource....:
| > | >
| > | > #How to: Enable Filtering for SqlDataSource Controls (Visual Studio)
| > | > http://msdn2.microsoft.com/en-us/library/ms178306.aspx
| > | >
| > | > e.g:
| > | >
| > | > <asp:CheckBox ID="Discontinued" runat="server" AutoPostBack="True"
/>
| > | > <asp:SqlDataSource ID="SqlDataSource1" runat="server"
| > | > ConnectionString="<%$
| > | > ConnectionStrings:LocalNorthWind %>"
| > | > SelectCommand="SELECT [ProductID], [ProductName],
| > | > [Discontinued], [ReorderLevel], [CategoryID] FROM [Products]"
| > | > FilterExpression="Discontinued = {0}"
| > | > OnSelected="SqlDataSource1_Selected">
| > | > <FilterParameters>
| > | > <asp:ControlParameter ControlID="Discontinued"
| > | > Type="boolean"
| > | > Name="disc" PropertyName="Checked" />
| > | > </FilterParameters>
| > | > </asp:SqlDataSource>
| > | >
| > | >
| > | > The above sql datasource setting the filter as "Discontinued = {0}"
,
| > and
| > | > the parameter is defined in the <Filterparameters> collection...
The
| > | > filter experssion is just the same as the Filter Expression we set
for
| > | > DataView class programmatically. And this filtering is done through
| > the
| > | > DataSet returned by the DataSourceControl rather than filtering at
| > | > database
| > | > level ( the "Where" statement
| > | > of the DataSoureControl is used to done database level filtering
.....
| > | >
| > | > Thanks,
| > | >
| > | > Steven Cheng
| > | > Microsoft Online Support
| > | >
| > | > Get Secure! www.microsoft.com/security
| > | > (This posting is provided "AS IS", with no warranties, and confers
no
| > | > rights.)
| > | >
| > | >
| > | >
| > | >
| > | > --------------------
| > | > | Reply-To: <wa********@newsgroups.nospam>
| > | > | From: <wa********@newsgroups.nospam>
| > | > | Subject: Filtering data inside the Gridview Control?
| > | > | Date: Wed, 14 Dec 2005 19:25:24 -0800
| > | > | Lines: 18
| > | > | X-Priority: 3
| > | > | X-MSMail-Priority: Normal
| > | > | X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
| > | > | X-RFC2646: Format=Flowed; Original
| > | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
| > | > | Message-ID: <e0*************@TK2MSFTNGP09.phx.gbl>
| > | > | Newsgroups: microsoft.public.dotnet.framework.aspnet
| > | > | NNTP-Posting-Host: ip-206.159.118.137.hdiss.net 206.159.118.137
| > | > | Path:
| > TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP09.phx.gbl
| > | > | Xref: TK2MSFTNGXA02.phx.gbl
| > | > microsoft.public.dotnet.framework.aspnet:365002
| > | > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
| > | > |
| > | > | Hello,
| > | > |
| > | > | Does anyone have an idea on how I can filter the data in the
| > gridview
| > | > | control that was returned by an sql query?
| > | > |
| > | > | I have a gridview that works fine when I populate it with data.
Now
| > I
| > | > want
| > | > | to look at that data and filter it based on what is in it.
| > | > |
| > | > | I know that this could have been done with data sets and data
views
| > in
| > | > | asp.net 1.1 but how is this done now in asp.net 2.0?
| > | > |
| > | > | Is there a way to do this?
| > | > |
| > | > | Thanks,
| > | > |
| > | > | J
| > | > |
| > | > |
| > | > |
| > | >
| > |
| > |
| > |
| >
|
|
|

Dec 19 '05 #6

P: n/a
Ok,

I figured it out. Here is what I did:

1. I bound both the grid view control and the list boxes to a dataset that
I created which pulls the data from the DB based on an SQL Statement.
2. I created a custom class that finds only distinct rows based on a table
and column. I call this class as the datasource of the data list controls
that I have on the page displaying the filtering options.
3. The SQL SELECT statement gets pulled from the querystring values in the
url. In other words the querystring values get dynamically ordered and
built into an select statement.
4. Every time a new query is ran the list boxes display values based on the
results returned. Thus, this filters your results.

Using the dataset really helps with the overhead because each control is
pulling from the same object.

Thanks,

J

"Steven Cheng[MSFT]" <st*****@online.microsoft.com> wrote in message
news:Ig**************@TK2MSFTNGXA02.phx.gbl...
Hi J,

Thanks for your response.
Of course manually loop the gridView and extract values from each row is
one possible appraoch, but that's not a good idea, either hard to code
also
have poor performance....
As for the further question you mentioned, I think it's better that you
move that query into a separate new datasource object, so that we can
cache
that query to improve performance(I think those query of DISTINCT values
should be cachable....). We can use the Select statement and Select
parameters to define parameter based query like:

=======================
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$
ConnectionStrings:LocalNorthWind %>"
SelectCommand="SELECT [Discontinued], [ProductID],
[ProductName], [UnitPrice] FROM [Products] WHERE ([Discontinued] =
@Discontinued)">
<SelectParameters>
<asp:Parameter DefaultValue="true" Name="Discontinued"
Type="Boolean" />
</SelectParameters>
</asp:SqlDataSource>
<asp:GridView ID="GridView2" runat="server"
AutoGenerateColumns="False" DataKeyNames="ProductID"
DataSourceID="SqlDataSource2">
<Columns>
<asp:CheckBoxField DataField="Discontinued"
HeaderText="Discontinued" SortExpression="Discontinued" />
<asp:BoundField DataField="ProductID"
HeaderText="ProductID" InsertVisible="False"
ReadOnly="True" SortExpression="ProductID" />
<asp:BoundField DataField="ProductName"
HeaderText="ProductName" SortExpression="ProductName" />
<asp:BoundField DataField="UnitPrice"
HeaderText="UnitPrice" SortExpression="UnitPrice" />
</Columns>
</asp:GridView>
======================

And we can also programmatically call the datasource.select method with
the
certain parameter instances as I've mentioned in the former message....

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
| Reply-To: <wa********@newsgroups.nospam>
| From: <wa********@newsgroups.nospam>
| References: <e0*************@TK2MSFTNGP09.phx.gbl>
<5w**************@TK2MSFTNGXA02.phx.gbl>
<ep**************@TK2MSFTNGP10.phx.gbl>
<dU**************@TK2MSFTNGXA02.phx.gbl>
| Subject: Re: Filtering data inside the Gridview Control?
| Date: Sun, 18 Dec 2005 14:48:48 -0800
| Lines: 231
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
| X-RFC2646: Format=Flowed; Original
| Message-ID: <u$**************@TK2MSFTNGP09.phx.gbl>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: ip-206.159.118.137.hdiss.net 206.159.118.137
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP09.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:365606
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Steven,
|
| I was told by someone that I should just loop through the gridview and
get
| the data that way. Is this incorrect?
|
| The way that you explain makes sense. Is the select method expression
just
| like SQL scripts? Because what I really need is to be able to do
something
| like, "SELECT DISTINCT column FROM table WHERE column='column'". For
the
| column that I want the data from, there are going to be many of the same
| values. All I want is to know what ones are there. Therefore I dont
need
| duplicates. So if there were:
|
| [column1]
| hat
| car
| car
| house
| hat
| hat
| hat
| car
|
| It would return back to me:
|
| hat
| car
| house
|
| I am then going to take these values and put them into a datalist
control
| that will display these as hyperlinks. Then when the user clicks on the
| hyperlink I can use that value as criteria for doing an sql query to the
DB
| thus repopulating the gridview and repopulating the datalist that
represent
| the values to filter by based on what was returned by the last sql query
to
| the DB.
|
| I hope that makes sense.
|
| I will try what you suggested and let you know how it works.
|
| Thanks,
|
| J
|
|
|
|
|
| "Steven Cheng[MSFT]" <st*****@online.microsoft.com> wrote in message
| news:dU**************@TK2MSFTNGXA02.phx.gbl...
| > Hi J,
| >
| > Thanks for the response. For searching, I'm afraid we have to do it at
| > datasource level since the GridView dosn't maintain orginal data
records
| > after databinding (only displaying databound data......). Also, the
| > DataSource control is mainly used to provide statically data
retrieveing
| > and work with databound controls, so we can manually call its methods
to
| > retrieve the Selected data, but can not affect the way DataBound
control
| > use it (we can only apply some parameters ...... in it...)
| >
| > So for your scenario, you can try manually call the SqlDataSource
| > control's
| > Select method with proper parameters then the returned object is the
| > datasouce (by default it is a DataView since the DataSourceMode is set
to
| > "DataSet" ). e.g:
| >
| > DataView dv = SqlDataSource1.Select(DataSourceSelectArguments.Em pty)
as
| > DataView;
| > Response.Write("<br>Returned: " + dv.Table.Select(.....) );
| >
| > Also, for such scenario, it is prefered that you not use
| > DataSourceControl,
| > just programmatically retrieve the DataSet/DataTable your self and
stored
| > in Cache, so that you can reuse it for searching later ......
| >
| > Thanks,
| >
| > Steven Cheng
| > Microsoft Online Support
| >
| > Get Secure! www.microsoft.com/security
| > (This posting is provided "AS IS", with no warranties, and confers no
| > rights.)
| >
| >
| >
| > --------------------
| > | Reply-To: <wa********@newsgroups.nospam>
| > | From: <wa********@newsgroups.nospam>
| > | References: <e0*************@TK2MSFTNGP09.phx.gbl>
| > <5w**************@TK2MSFTNGXA02.phx.gbl>
| > | Subject: Re: Filtering data inside the Gridview Control?
| > | Date: Thu, 15 Dec 2005 01:48:11 -0800
| > | Lines: 110
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
| > | X-RFC2646: Format=Flowed; Original
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
| > | Message-ID: <ep**************@TK2MSFTNGP10.phx.gbl>
| > | Newsgroups: microsoft.public.dotnet.framework.aspnet
| > | NNTP-Posting-Host: ip-206.159.118.137.hdiss.net 206.159.118.137
| > | Path:
TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP10.phx.gbl
| > | Xref: TK2MSFTNGXA02.phx.gbl
| > microsoft.public.dotnet.framework.aspnet:365043
| > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
| > |
| > | Steven,
| > |
| > | Cool that helped me with filtering the rows but I have one other
| > question.
| > |
| > | How do I search through the gridview? Would I do this at the
| > sqldatasource
| > | level?
| > |
| > | I figured that I sould search with the datatable.select but how do I
| > access
| > | the datatable of the sqldatasource?
| > |
| > | Thanks for your help
| > |
| > | J
| > |
| > |
| > | "Steven Cheng[MSFT]" <st*****@online.microsoft.com> wrote in message
| > | news:5w**************@TK2MSFTNGXA02.phx.gbl...
| > | > Hi J,
| > | >
| > | > Welcome to ASPNET newsgroup.
| > | > As for the filtering data displayed in the asp.net GridView
control
| > | > question, based on my understanding, we should do this at
DataSource
| > | > level... I think you're using a SqlDataSource to provide the data
| > records
| > | > to the GridView , yes? If so, you can have alook at the
following
| > msdn
| > | > reference about using filtering function of the SqlDataSource....:
| > | >
| > | > #How to: Enable Filtering for SqlDataSource Controls (Visual
Studio)
| > | > http://msdn2.microsoft.com/en-us/library/ms178306.aspx
| > | >
| > | > e.g:
| > | >
| > | > <asp:CheckBox ID="Discontinued" runat="server"
AutoPostBack="True"
/>
| > | > <asp:SqlDataSource ID="SqlDataSource1" runat="server"
| > | > ConnectionString="<%$
| > | > ConnectionStrings:LocalNorthWind %>"
| > | > SelectCommand="SELECT [ProductID], [ProductName],
| > | > [Discontinued], [ReorderLevel], [CategoryID] FROM [Products]"
| > | > FilterExpression="Discontinued = {0}"
| > | > OnSelected="SqlDataSource1_Selected">
| > | > <FilterParameters>
| > | > <asp:ControlParameter ControlID="Discontinued"
| > | > Type="boolean"
| > | > Name="disc" PropertyName="Checked" />
| > | > </FilterParameters>
| > | > </asp:SqlDataSource>
| > | >
| > | >
| > | > The above sql datasource setting the filter as "Discontinued =
{0}"
,
| > and
| > | > the parameter is defined in the <Filterparameters> collection...
The
| > | > filter experssion is just the same as the Filter Expression we set
for
| > | > DataView class programmatically. And this filtering is done
through
| > the
| > | > DataSet returned by the DataSourceControl rather than filtering at
| > | > database
| > | > level ( the "Where" statement
| > | > of the DataSoureControl is used to done database level filtering
....
| > | >
| > | > Thanks,
| > | >
| > | > Steven Cheng
| > | > Microsoft Online Support
| > | >
| > | > Get Secure! www.microsoft.com/security
| > | > (This posting is provided "AS IS", with no warranties, and confers
no
| > | > rights.)
| > | >
| > | >
| > | >
| > | >
| > | > --------------------
| > | > | Reply-To: <wa********@newsgroups.nospam>
| > | > | From: <wa********@newsgroups.nospam>
| > | > | Subject: Filtering data inside the Gridview Control?
| > | > | Date: Wed, 14 Dec 2005 19:25:24 -0800
| > | > | Lines: 18
| > | > | X-Priority: 3
| > | > | X-MSMail-Priority: Normal
| > | > | X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
| > | > | X-RFC2646: Format=Flowed; Original
| > | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
| > | > | Message-ID: <e0*************@TK2MSFTNGP09.phx.gbl>
| > | > | Newsgroups: microsoft.public.dotnet.framework.aspnet
| > | > | NNTP-Posting-Host: ip-206.159.118.137.hdiss.net 206.159.118.137
| > | > | Path:
| > TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP09.phx.gbl
| > | > | Xref: TK2MSFTNGXA02.phx.gbl
| > | > microsoft.public.dotnet.framework.aspnet:365002
| > | > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
| > | > |
| > | > | Hello,
| > | > |
| > | > | Does anyone have an idea on how I can filter the data in the
| > gridview
| > | > | control that was returned by an sql query?
| > | > |
| > | > | I have a gridview that works fine when I populate it with data.
Now
| > I
| > | > want
| > | > | to look at that data and filter it based on what is in it.
| > | > |
| > | > | I know that this could have been done with data sets and data
views
| > in
| > | > | asp.net 1.1 but how is this done now in asp.net 2.0?
| > | > |
| > | > | Is there a way to do this?
| > | > |
| > | > | Thanks,
| > | > |
| > | > | J
| > | > |
| > | > |
| > | > |
| > | >
| > |
| > |
| > |
| >
|
|
|

Dec 21 '05 #7

P: n/a
Cool! So you use the ObjectDataSource with custom class currently? That's
also a good idea....

Thanks for your further followup.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
| Reply-To: <wa********@newsgroups.nospam>
| From: <wa********@newsgroups.nospam>
| References: <e0*************@TK2MSFTNGP09.phx.gbl>
<5w**************@TK2MSFTNGXA02.phx.gbl>
<ep**************@TK2MSFTNGP10.phx.gbl>
<dU**************@TK2MSFTNGXA02.phx.gbl>
<u$**************@TK2MSFTNGP09.phx.gbl>
<Ig**************@TK2MSFTNGXA02.phx.gbl>
| Subject: Re: Filtering data inside the Gridview Control?
| Date: Wed, 21 Dec 2005 14:52:32 -0800
| Lines: 378
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
| X-RFC2646: Format=Flowed; Original
| Message-ID: <OY**************@TK2MSFTNGP10.phx.gbl>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: ip-206.159.118.137.hdiss.net 206.159.118.137
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP10.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:366427
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Ok,
|
| I figured it out. Here is what I did:
|
| 1. I bound both the grid view control and the list boxes to a dataset
that
| I created which pulls the data from the DB based on an SQL Statement.
| 2. I created a custom class that finds only distinct rows based on a
table
| and column. I call this class as the datasource of the data list
controls
| that I have on the page displaying the filtering options.
| 3. The SQL SELECT statement gets pulled from the querystring values in
the
| url. In other words the querystring values get dynamically ordered and
| built into an select statement.
| 4. Every time a new query is ran the list boxes display values based on
the
| results returned. Thus, this filters your results.
|
| Using the dataset really helps with the overhead because each control is
| pulling from the same object.
|
| Thanks,
|
| J
|
|
|
|
|
| "Steven Cheng[MSFT]" <st*****@online.microsoft.com> wrote in message
| news:Ig**************@TK2MSFTNGXA02.phx.gbl...
| > Hi J,
| >
| > Thanks for your response.
| > Of course manually loop the gridView and extract values from each row is
| > one possible appraoch, but that's not a good idea, either hard to code
| > also
| > have poor performance....
| > As for the further question you mentioned, I think it's better that you
| > move that query into a separate new datasource object, so that we can
| > cache
| > that query to improve performance(I think those query of DISTINCT values
| > should be cachable....). We can use the Select statement and Select
| > parameters to define parameter based query like:
| >
| > =======================
| > <asp:SqlDataSource ID="SqlDataSource2" runat="server"
| > ConnectionString="<%$
| > ConnectionStrings:LocalNorthWind %>"
| > SelectCommand="SELECT [Discontinued], [ProductID],
| > [ProductName], [UnitPrice] FROM [Products] WHERE ([Discontinued] =
| > @Discontinued)">
| > <SelectParameters>
| > <asp:Parameter DefaultValue="true" Name="Discontinued"
| > Type="Boolean" />
| > </SelectParameters>
| > </asp:SqlDataSource>
| > <asp:GridView ID="GridView2" runat="server"
| > AutoGenerateColumns="False" DataKeyNames="ProductID"
| > DataSourceID="SqlDataSource2">
| > <Columns>
| > <asp:CheckBoxField DataField="Discontinued"
| > HeaderText="Discontinued" SortExpression="Discontinued" />
| > <asp:BoundField DataField="ProductID"
| > HeaderText="ProductID" InsertVisible="False"
| > ReadOnly="True" SortExpression="ProductID" />
| > <asp:BoundField DataField="ProductName"
| > HeaderText="ProductName" SortExpression="ProductName" />
| > <asp:BoundField DataField="UnitPrice"
| > HeaderText="UnitPrice" SortExpression="UnitPrice" />
| > </Columns>
| > </asp:GridView>
| > ======================
| >
| > And we can also programmatically call the datasource.select method with
| > the
| > certain parameter instances as I've mentioned in the former message....
| >
| > Thanks,
| >
| > Steven Cheng
| > Microsoft Online Support
| >
| > Get Secure! www.microsoft.com/security
| > (This posting is provided "AS IS", with no warranties, and confers no
| > rights.)
| >
| >
| >
| >
| >
| > --------------------
| > | Reply-To: <wa********@newsgroups.nospam>
| > | From: <wa********@newsgroups.nospam>
| > | References: <e0*************@TK2MSFTNGP09.phx.gbl>
| > <5w**************@TK2MSFTNGXA02.phx.gbl>
| > <ep**************@TK2MSFTNGP10.phx.gbl>
| > <dU**************@TK2MSFTNGXA02.phx.gbl>
| > | Subject: Re: Filtering data inside the Gridview Control?
| > | Date: Sun, 18 Dec 2005 14:48:48 -0800
| > | Lines: 231
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
| > | X-RFC2646: Format=Flowed; Original
| > | Message-ID: <u$**************@TK2MSFTNGP09.phx.gbl>
| > | Newsgroups: microsoft.public.dotnet.framework.aspnet
| > | NNTP-Posting-Host: ip-206.159.118.137.hdiss.net 206.159.118.137
| > | Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP09.phx.gbl
| > | Xref: TK2MSFTNGXA02.phx.gbl
| > microsoft.public.dotnet.framework.aspnet:365606
| > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
| > |
| > | Steven,
| > |
| > | I was told by someone that I should just loop through the gridview and
| > get
| > | the data that way. Is this incorrect?
| > |
| > | The way that you explain makes sense. Is the select method expression
| > just
| > | like SQL scripts? Because what I really need is to be able to do
| > something
| > | like, "SELECT DISTINCT column FROM table WHERE column='column'". For
| > the
| > | column that I want the data from, there are going to be many of the
same
| > | values. All I want is to know what ones are there. Therefore I dont
| > need
| > | duplicates. So if there were:
| > |
| > | [column1]
| > | hat
| > | car
| > | car
| > | house
| > | hat
| > | hat
| > | hat
| > | car
| > |
| > | It would return back to me:
| > |
| > | hat
| > | car
| > | house
| > |
| > | I am then going to take these values and put them into a datalist
| > control
| > | that will display these as hyperlinks. Then when the user clicks on
the
| > | hyperlink I can use that value as criteria for doing an sql query to
the
| > DB
| > | thus repopulating the gridview and repopulating the datalist that
| > represent
| > | the values to filter by based on what was returned by the last sql
query
| > to
| > | the DB.
| > |
| > | I hope that makes sense.
| > |
| > | I will try what you suggested and let you know how it works.
| > |
| > | Thanks,
| > |
| > | J
| > |
| > |
| > |
| > |
| > |
| > | "Steven Cheng[MSFT]" <st*****@online.microsoft.com> wrote in message
| > | news:dU**************@TK2MSFTNGXA02.phx.gbl...
| > | > Hi J,
| > | >
| > | > Thanks for the response. For searching, I'm afraid we have to do it
at
| > | > datasource level since the GridView dosn't maintain orginal data
| > records
| > | > after databinding (only displaying databound data......). Also,
the
| > | > DataSource control is mainly used to provide statically data
| > retrieveing
| > | > and work with databound controls, so we can manually call its
methods
| > to
| > | > retrieve the Selected data, but can not affect the way DataBound
| > control
| > | > use it (we can only apply some parameters ...... in it...)
| > | >
| > | > So for your scenario, you can try manually call the SqlDataSource
| > | > control's
| > | > Select method with proper parameters then the returned object is the
| > | > datasouce (by default it is a DataView since the DataSourceMode is
set
| > to
| > | > "DataSet" ). e.g:
| > | >
| > | > DataView dv =
SqlDataSource1.Select(DataSourceSelectArguments.Em pty)
| > as
| > | > DataView;
| > | > Response.Write("<br>Returned: " + dv.Table.Select(.....) );
| > | >
| > | > Also, for such scenario, it is prefered that you not use
| > | > DataSourceControl,
| > | > just programmatically retrieve the DataSet/DataTable your self and
| > stored
| > | > in Cache, so that you can reuse it for searching later ......
| > | >
| > | > Thanks,
| > | >
| > | > Steven Cheng
| > | > Microsoft Online Support
| > | >
| > | > Get Secure! www.microsoft.com/security
| > | > (This posting is provided "AS IS", with no warranties, and confers
no
| > | > rights.)
| > | >
| > | >
| > | >
| > | > --------------------
| > | > | Reply-To: <wa********@newsgroups.nospam>
| > | > | From: <wa********@newsgroups.nospam>
| > | > | References: <e0*************@TK2MSFTNGP09.phx.gbl>
| > | > <5w**************@TK2MSFTNGXA02.phx.gbl>
| > | > | Subject: Re: Filtering data inside the Gridview Control?
| > | > | Date: Thu, 15 Dec 2005 01:48:11 -0800
| > | > | Lines: 110
| > | > | X-Priority: 3
| > | > | X-MSMail-Priority: Normal
| > | > | X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
| > | > | X-RFC2646: Format=Flowed; Original
| > | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
| > | > | Message-ID: <ep**************@TK2MSFTNGP10.phx.gbl>
| > | > | Newsgroups: microsoft.public.dotnet.framework.aspnet
| > | > | NNTP-Posting-Host: ip-206.159.118.137.hdiss.net 206.159.118.137
| > | > | Path:
| > TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP10.phx.gbl
| > | > | Xref: TK2MSFTNGXA02.phx.gbl
| > | > microsoft.public.dotnet.framework.aspnet:365043
| > | > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
| > | > |
| > | > | Steven,
| > | > |
| > | > | Cool that helped me with filtering the rows but I have one other
| > | > question.
| > | > |
| > | > | How do I search through the gridview? Would I do this at the
| > | > sqldatasource
| > | > | level?
| > | > |
| > | > | I figured that I sould search with the datatable.select but how
do I
| > | > access
| > | > | the datatable of the sqldatasource?
| > | > |
| > | > | Thanks for your help
| > | > |
| > | > | J
| > | > |
| > | > |
| > | > | "Steven Cheng[MSFT]" <st*****@online.microsoft.com> wrote in
message
| > | > | news:5w**************@TK2MSFTNGXA02.phx.gbl...
| > | > | > Hi J,
| > | > | >
| > | > | > Welcome to ASPNET newsgroup.
| > | > | > As for the filtering data displayed in the asp.net GridView
| > control
| > | > | > question, based on my understanding, we should do this at
| > DataSource
| > | > | > level... I think you're using a SqlDataSource to provide the
data
| > | > records
| > | > | > to the GridView , yes? If so, you can have alook at the
| > following
| > | > msdn
| > | > | > reference about using filtering function of the
SqlDataSource....:
| > | > | >
| > | > | > #How to: Enable Filtering for SqlDataSource Controls (Visual
| > Studio)
| > | > | > http://msdn2.microsoft.com/en-us/library/ms178306.aspx
| > | > | >
| > | > | > e.g:
| > | > | >
| > | > | > <asp:CheckBox ID="Discontinued" runat="server"
| > AutoPostBack="True"
| > />
| > | > | > <asp:SqlDataSource ID="SqlDataSource1" runat="server"
| > | > | > ConnectionString="<%$
| > | > | > ConnectionStrings:LocalNorthWind %>"
| > | > | > SelectCommand="SELECT [ProductID], [ProductName],
| > | > | > [Discontinued], [ReorderLevel], [CategoryID] FROM [Products]"
| > | > | > FilterExpression="Discontinued = {0}"
| > | > | > OnSelected="SqlDataSource1_Selected">
| > | > | > <FilterParameters>
| > | > | > <asp:ControlParameter ControlID="Discontinued"
| > | > | > Type="boolean"
| > | > | > Name="disc" PropertyName="Checked" />
| > | > | > </FilterParameters>
| > | > | > </asp:SqlDataSource>
| > | > | >
| > | > | >
| > | > | > The above sql datasource setting the filter as "Discontinued =
| > {0}"
| > ,
| > | > and
| > | > | > the parameter is defined in the <Filterparameters> collection...
| > The
| > | > | > filter experssion is just the same as the Filter Expression we
set
| > for
| > | > | > DataView class programmatically. And this filtering is done
| > through
| > | > the
| > | > | > DataSet returned by the DataSourceControl rather than filtering
at
| > | > | > database
| > | > | > level ( the "Where" statement
| > | > | > of the DataSoureControl is used to done database level filtering
| > ....
| > | > | >
| > | > | > Thanks,
| > | > | >
| > | > | > Steven Cheng
| > | > | > Microsoft Online Support
| > | > | >
| > | > | > Get Secure! www.microsoft.com/security
| > | > | > (This posting is provided "AS IS", with no warranties, and
confers
| > no
| > | > | > rights.)
| > | > | >
| > | > | >
| > | > | >
| > | > | >
| > | > | > --------------------
| > | > | > | Reply-To: <wa********@newsgroups.nospam>
| > | > | > | From: <wa********@newsgroups.nospam>
| > | > | > | Subject: Filtering data inside the Gridview Control?
| > | > | > | Date: Wed, 14 Dec 2005 19:25:24 -0800
| > | > | > | Lines: 18
| > | > | > | X-Priority: 3
| > | > | > | X-MSMail-Priority: Normal
| > | > | > | X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
| > | > | > | X-RFC2646: Format=Flowed; Original
| > | > | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
| > | > | > | Message-ID: <e0*************@TK2MSFTNGP09.phx.gbl>
| > | > | > | Newsgroups: microsoft.public.dotnet.framework.aspnet
| > | > | > | NNTP-Posting-Host: ip-206.159.118.137.hdiss.net
206.159.118.137
| > | > | > | Path:
| > | > TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP09.phx.gbl
| > | > | > | Xref: TK2MSFTNGXA02.phx.gbl
| > | > | > microsoft.public.dotnet.framework.aspnet:365002
| > | > | > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
| > | > | > |
| > | > | > | Hello,
| > | > | > |
| > | > | > | Does anyone have an idea on how I can filter the data in the
| > | > gridview
| > | > | > | control that was returned by an sql query?
| > | > | > |
| > | > | > | I have a gridview that works fine when I populate it with
data.
| > Now
| > | > I
| > | > | > want
| > | > | > | to look at that data and filter it based on what is in it.
| > | > | > |
| > | > | > | I know that this could have been done with data sets and data
| > views
| > | > in
| > | > | > | asp.net 1.1 but how is this done now in asp.net 2.0?
| > | > | > |
| > | > | > | Is there a way to do this?
| > | > | > |
| > | > | > | Thanks,
| > | > | > |
| > | > | > | J
| > | > | > |
| > | > | > |
| > | > | > |
| > | > | >
| > | > |
| > | > |
| > | > |
| > | >
| > |
| > |
| > |
| >
|
|
|

Dec 22 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.