Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Filtering data inside the Gridview Control?

Reply
Thread Tools

Filtering data inside the Gridview Control?

 
 
Guest
Posts: n/a
 
      12-15-2005
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


 
Reply With Quote
 
 
 
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      12-15-2005
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: <(E-Mail Removed)>
| From: <(E-Mail Removed)>
| 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: <(E-Mail Removed)>
| 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
|
|
|

 
Reply With Quote
 
 
 
 
Guest
Posts: n/a
 
      12-15-2005
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]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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: <(E-Mail Removed)>
> | From: <(E-Mail Removed)>
> | 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: <(E-Mail Removed)>
> | 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
> |
> |
> |
>



 
Reply With Quote
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      12-16-2005
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: <(E-Mail Removed)>
| From: <(E-Mail Removed)>
| References: <(E-Mail Removed)>
<(E-Mail Removed)>
| 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: <(E-Mail Removed)>
| 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]" <(E-Mail Removed)> wrote in message
| news:(E-Mail Removed)...
| > 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: <(E-Mail Removed)>
| > | From: <(E-Mail Removed)>
| > | 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: <(E-Mail Removed)>
| > | 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
| > |
| > |
| > |
| >
|
|
|

 
Reply With Quote
 
Guest
Posts: n/a
 
      12-18-2005
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]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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: <(E-Mail Removed)>
> | From: <(E-Mail Removed)>
> | References: <(E-Mail Removed)>
> <(E-Mail Removed)>
> | 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: <(E-Mail Removed)>
> | 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]" <(E-Mail Removed)> wrote in message
> | news:(E-Mail Removed)...
> | > 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: <(E-Mail Removed)>
> | > | From: <(E-Mail Removed)>
> | > | 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: <(E-Mail Removed)>
> | > | 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
> | > |
> | > |
> | > |
> | >
> |
> |
> |
>



 
Reply With Quote
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      12-19-2005
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>
<asparameter 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: <(E-Mail Removed)>
| From: <(E-Mail Removed)>
| References: <(E-Mail Removed)>
<(E-Mail Removed)>
<(E-Mail Removed)>
<(E-Mail Removed)>
| 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$(E-Mail Removed)>
| 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]" <(E-Mail Removed)> wrote in message
| news:(E-Mail Removed)...
| > 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: <(E-Mail Removed)>
| > | From: <(E-Mail Removed)>
| > | References: <(E-Mail Removed)>
| > <(E-Mail Removed)>
| > | 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: <(E-Mail Removed)>
| > | 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]" <(E-Mail Removed)> wrote in message
| > | news:(E-Mail Removed)...
| > | > 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: <(E-Mail Removed)>
| > | > | From: <(E-Mail Removed)>
| > | > | 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: <(E-Mail Removed)>
| > | > | 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
| > | > |
| > | > |
| > | > |
| > | >
| > |
| > |
| > |
| >
|
|
|

 
Reply With Quote
 
Guest
Posts: n/a
 
      12-21-2005
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]" <(E-Mail Removed)> wrote in message
news:IgU$(E-Mail Removed)...
> 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>
> <asparameter 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: <(E-Mail Removed)>
> | From: <(E-Mail Removed)>
> | References: <(E-Mail Removed)>
> <(E-Mail Removed)>
> <(E-Mail Removed)>
> <(E-Mail Removed)>
> | 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$(E-Mail Removed)>
> | 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]" <(E-Mail Removed)> wrote in message
> | news:(E-Mail Removed)...
> | > 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: <(E-Mail Removed)>
> | > | From: <(E-Mail Removed)>
> | > | References: <(E-Mail Removed)>
> | > <(E-Mail Removed)>
> | > | 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: <(E-Mail Removed)>
> | > | 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]" <(E-Mail Removed)> wrote in message
> | > | news:(E-Mail Removed)...
> | > | > 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: <(E-Mail Removed)>
> | > | > | From: <(E-Mail Removed)>
> | > | > | 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: <(E-Mail Removed)>
> | > | > | 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
> | > | > |
> | > | > |
> | > | > |
> | > | >
> | > |
> | > |
> | > |
> | >
> |
> |
> |
>



 
Reply With Quote
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      12-22-2005
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: <(E-Mail Removed)>
| From: <(E-Mail Removed)>
| References: <(E-Mail Removed)>
<(E-Mail Removed)>
<(E-Mail Removed)>
<(E-Mail Removed)>
<u$(E-Mail Removed)>
<IgU$(E-Mail Removed)>
| 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: <(E-Mail Removed)>
| 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]" <(E-Mail Removed)> wrote in message
| news:IgU$(E-Mail Removed)...
| > 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>
| > <asparameter 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: <(E-Mail Removed)>
| > | From: <(E-Mail Removed)>
| > | References: <(E-Mail Removed)>
| > <(E-Mail Removed)>
| > <(E-Mail Removed)>
| > <(E-Mail Removed)>
| > | 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$(E-Mail Removed)>
| > | 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]" <(E-Mail Removed)> wrote in message
| > | news:(E-Mail Removed)...
| > | > 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: <(E-Mail Removed)>
| > | > | From: <(E-Mail Removed)>
| > | > | References: <(E-Mail Removed)>
| > | > <(E-Mail Removed)>
| > | > | 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: <(E-Mail Removed)>
| > | > | 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]" <(E-Mail Removed)> wrote in
message
| > | > | news:(E-Mail Removed)...
| > | > | > 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: <(E-Mail Removed)>
| > | > | > | From: <(E-Mail Removed)>
| > | > | > | 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: <(E-Mail Removed)>
| > | > | > | 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
| > | > | > |
| > | > | > |
| > | > | > |
| > | > | >
| > | > |
| > | > |
| > | > |
| > | >
| > |
| > |
| > |
| >
|
|
|

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
get data that fills gridview inside the gridview Sergio E. ASP .Net Web Controls 0 08-08-2007 01:15 PM
RowCommand: accessing ObjectDataSource from inside gridview inside a repeater? HockeyFan ASP .Net 1 07-04-2007 05:49 AM
Creating a new data structure while filtering its data origin. Python 5 03-30-2007 02:37 AM
Add Row to datatable bound to gridview inside a gridview Elmo Watson ASP .Net 0 08-17-2006 02:26 PM
Gridview inside Gridview little problems... Carlos Albert ASP .Net 1 12-06-2005 05:31 PM



Advertisments