472,980 Members | 2,083 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Filtering data inside the Gridview Control?

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
7 14734
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Bill Manring | last post by:
I am writing a very simple web application using VS 2005 and a SQL Server Database. I am just starting to experiment wth .NET 2.0 and I am trying out the supposedly improved databinding. I...
1
by: SomebodyElse | last post by:
Hi. Apologies if this has been asked here before - I've searched & searched but can't find anything. It's probably my serach parameters, but I'm having trouble even describing it to a search...
5
by: sutphinwb | last post by:
Hi - This could be a simple question. When I relate two tables in a datasetet, how do I get that relation to show up in a GridView? The only way I've done it, is to create a separate table in the...
1
by: Nam | last post by:
I have a DropDownList control in a TemplateField inside my GridView How do I access this control’s SelectedIndexChanged event in codeBehind page? I don’t see the ID “DropDownList1” of...
2
by: kevinpond | last post by:
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...
3
by: Harry Haller | last post by:
Hello, I want to implement a generic list which will be used to display 7 columns in a GridView. One should be able to sort, filter and page each of the 7 columns. Ideally the filter should be...
1
by: weird0 | last post by:
I have created a GridView and dynamically added data to it by creating a DataTable(as advised) and bound it with a reader. Then, assigned the DataSource of GridView to DataTable. But even that aint...
11
by: =?Utf-8?B?QW5u?= | last post by:
Hello, I want to send an email when the Insert button is clicked that includes data entered on the form. I am using asp.net 2.0 and an insert template. I receive the email OK, but there is no...
1
by: HockeyFan | last post by:
protected void gvAuthorizedSigners_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "EmptyInsert") { odsAuthorizedSigners.Insert(); return; } if (e.CommandName...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

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.