|
.net
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
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 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.) -------------------- Show quote | Reply-To: <washoetech@newsgroups.nospam> microsoft.public.dotnet.framework.aspnet:365002| From: <washoetech@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: <e0hdwcSAGHA.***@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!TK2MSFTNGP09.phx.gbl | Xref: TK2MSFTNGXA02.phx.gbl Show quote | 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 | | | 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 Show quote "Steven Cheng[MSFT]" <stch***@online.microsoft.com> wrote in message news:5wVyqgVAGHA.1240@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: <washoetech@newsgroups.nospam> > | From: <washoetech@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: <e0hdwcSAGHA.***@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!TK2MSFTNGP09.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 > | > | > | > 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.Empty) 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: <washoetech@newsgroups.nospam> <5wVyqgVAGHA.1***@TK2MSFTNGXA02.phx.gbl>| From: <washoetech@newsgroups.nospam> | References: <e0hdwcSAGHA.***@TK2MSFTNGP09.phx.gbl> | Subject: Re: Filtering data inside the Gridview Control? microsoft.public.dotnet.framework.aspnet:365043| 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: <ep7zqyVAGHA.3***@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!TK2MSFTNGP10.phx.gbl | Xref: TK2MSFTNGXA02.phx.gbl Show quote | 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]" <stch***@online.microsoft.com> wrote in message | news:5wVyqgVAGHA.1240@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: <washoetech@newsgroups.nospam> | > | From: <washoetech@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: <e0hdwcSAGHA.***@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!TK2MSFTNGP09.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 | > | | > | | > | | > | | | 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 Show quote "Steven Cheng[MSFT]" <stch***@online.microsoft.com> wrote in message news:dUlzaweAGHA.1240@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.Empty) 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: <washoetech@newsgroups.nospam> > | From: <washoetech@newsgroups.nospam> > | References: <e0hdwcSAGHA.***@TK2MSFTNGP09.phx.gbl> > <5wVyqgVAGHA.1***@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: <ep7zqyVAGHA.3***@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!TK2MSFTNGP10.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]" <stch***@online.microsoft.com> wrote in message > | news:5wVyqgVAGHA.1240@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: <washoetech@newsgroups.nospam> > | > | From: <washoetech@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: <e0hdwcSAGHA.***@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!TK2MSFTNGP09.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 > | > | > | > | > | > | > | > > | > | > | > 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: <washoetech@newsgroups.nospam> <5wVyqgVAGHA.1***@TK2MSFTNGXA02.phx.gbl> | From: <washoetech@newsgroups.nospam> | References: <e0hdwcSAGHA.***@TK2MSFTNGP09.phx.gbl> <ep7zqyVAGHA.3***@TK2MSFTNGP10.phx.gbl> <dUlzaweAGHA.1***@TK2MSFTNGXA02.phx.gbl> | Subject: Re: Filtering data inside the Gridview Control? microsoft.public.dotnet.framework.aspnet:365606| 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$Cn1UCBGHA.4***@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!TK2MSFTNGP09.phx.gbl | Xref: TK2MSFTNGXA02.phx.gbl Show quote | 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]" <stch***@online.microsoft.com> wrote in message | news:dUlzaweAGHA.1240@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.Empty) 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: <washoetech@newsgroups.nospam> | > | From: <washoetech@newsgroups.nospam> | > | References: <e0hdwcSAGHA.***@TK2MSFTNGP09.phx.gbl> | > <5wVyqgVAGHA.1***@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: <ep7zqyVAGHA.3***@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!TK2MSFTNGP10.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]" <stch***@online.microsoft.com> wrote in message | > | news:5wVyqgVAGHA.1240@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: <washoetech@newsgroups.nospam> | > | > | From: <washoetech@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: <e0hdwcSAGHA.***@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!TK2MSFTNGP09.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 | > | > | | > | > | | > | > | | > | > | > | | > | | > | | > | | | 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 Show quote "Steven Cheng[MSFT]" <stch***@online.microsoft.com> wrote in message news:IgU$cYIBGHA.3764@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: <washoetech@newsgroups.nospam> > | From: <washoetech@newsgroups.nospam> > | References: <e0hdwcSAGHA.***@TK2MSFTNGP09.phx.gbl> > <5wVyqgVAGHA.1***@TK2MSFTNGXA02.phx.gbl> > <ep7zqyVAGHA.3***@TK2MSFTNGP10.phx.gbl> > <dUlzaweAGHA.1***@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$Cn1UCBGHA.4***@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!TK2MSFTNGP09.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]" <stch***@online.microsoft.com> wrote in message > | news:dUlzaweAGHA.1240@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.Empty) > 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: <washoetech@newsgroups.nospam> > | > | From: <washoetech@newsgroups.nospam> > | > | References: <e0hdwcSAGHA.***@TK2MSFTNGP09.phx.gbl> > | > <5wVyqgVAGHA.1***@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: <ep7zqyVAGHA.3***@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!TK2MSFTNGP10.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]" <stch***@online.microsoft.com> wrote in message > | > | news:5wVyqgVAGHA.1240@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: <washoetech@newsgroups.nospam> > | > | > | From: <washoetech@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: <e0hdwcSAGHA.***@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!TK2MSFTNGP09.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 > | > | > | > | > | > | > | > | > | > | > | > > | > | > | > | > | > | > | > > | > | > | > 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: <washoetech@newsgroups.nospam> <5wVyqgVAGHA.1***@TK2MSFTNGXA02.phx.gbl> | From: <washoetech@newsgroups.nospam> | References: <e0hdwcSAGHA.***@TK2MSFTNGP09.phx.gbl> <ep7zqyVAGHA.3***@TK2MSFTNGP10.phx.gbl> <dUlzaweAGHA.1***@TK2MSFTNGXA02.phx.gbl> <u$Cn1UCBGHA.4***@TK2MSFTNGP09.phx.gbl> <IgU$cYIBGHA.3***@TK2MSFTNGXA02.phx.gbl> | Subject: Re: Filtering data inside the Gridview Control? microsoft.public.dotnet.framework.aspnet:366427| 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: <OYph5EoBGHA.4***@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!TK2MSFTNGP10.phx.gbl | Xref: TK2MSFTNGXA02.phx.gbl Show quote | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet SqlDataSource1.Select(DataSourceSelectArguments.Empty) | | 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]" <stch***@online.microsoft.com> wrote in message | news:IgU$cYIBGHA.3764@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: <washoetech@newsgroups.nospam> | > | From: <washoetech@newsgroups.nospam> | > | References: <e0hdwcSAGHA.***@TK2MSFTNGP09.phx.gbl> | > <5wVyqgVAGHA.1***@TK2MSFTNGXA02.phx.gbl> | > <ep7zqyVAGHA.3***@TK2MSFTNGP10.phx.gbl> | > <dUlzaweAGHA.1***@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$Cn1UCBGHA.4***@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!TK2MSFTNGP09.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]" <stch***@online.microsoft.com> wrote in message | > | news:dUlzaweAGHA.1240@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 = Show quote | > as 206.159.118.137| > | > 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: <washoetech@newsgroups.nospam> | > | > | From: <washoetech@newsgroups.nospam> | > | > | References: <e0hdwcSAGHA.***@TK2MSFTNGP09.phx.gbl> | > | > <5wVyqgVAGHA.1***@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: <ep7zqyVAGHA.3***@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!TK2MSFTNGP10.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]" <stch***@online.microsoft.com> wrote in message | > | > | news:5wVyqgVAGHA.1240@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: <washoetech@newsgroups.nospam> | > | > | > | From: <washoetech@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: <e0hdwcSAGHA.***@TK2MSFTNGP09.phx.gbl> | > | > | > | Newsgroups: microsoft.public.dotnet.framework.aspnet | > | > | > | NNTP-Posting-Host: ip-206.159.118.137.hdiss.net Show quote | > | > | > | Path: | > | > TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP09.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 | > | > | > | | > | > | > | | > | > | > | | > | > | > | > | > | | > | > | | > | > | | > | > | > | | > | | > | | > | | |
Other interesting topics
it's THREE times that i post Really wanna solve this!!!!!
VS 2005 : why is the default for AutoEventWireup different for C# and VB.NET ? New ASP project Won't recognize my user name and password! forcing new session id without closing browser Excel.exe Process stays open in my "Task Manager" (C# ASP.Net Development) |
|||||||||||||||||||||||