Filtering data inside the Gridview Control?

Discussion in 'ASP .Net' started by Guest, Dec 15, 2005.

  1. Guest

    Guest Guest

    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
     
    Guest, Dec 15, 2005
    #1
    1. Advertising

  2. 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: <>
    | From: <>
    | 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: <>
    | 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 Cheng[MSFT], Dec 15, 2005
    #2
    1. Advertising

  3. Guest

    Guest Guest

    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]" <> wrote in message
    news:...
    > 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: <>
    > | From: <>
    > | 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: <>
    > | 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
    > |
    > |
    > |
    >
     
    Guest, Dec 15, 2005
    #3
  4. 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: <>
    | From: <>
    | References: <>
    <>
    | 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: <>
    | 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]" <> wrote in message
    | news:...
    | > 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: <>
    | > | From: <>
    | > | 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: <>
    | > | 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 Cheng[MSFT], Dec 16, 2005
    #4
  5. Guest

    Guest Guest

    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]" <> wrote in message
    news:...
    > 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: <>
    > | From: <>
    > | References: <>
    > <>
    > | 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: <>
    > | 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]" <> wrote in message
    > | news:...
    > | > 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: <>
    > | > | From: <>
    > | > | 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: <>
    > | > | 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
    > | > |
    > | > |
    > | > |
    > | >
    > |
    > |
    > |
    >
     
    Guest, Dec 18, 2005
    #5
  6. 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: <>
    | From: <>
    | References: <>
    <>
    <>
    <>
    | 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$>
    | 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]" <> wrote in message
    | news:...
    | > 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: <>
    | > | From: <>
    | > | References: <>
    | > <>
    | > | 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: <>
    | > | 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]" <> wrote in message
    | > | news:...
    | > | > 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: <>
    | > | > | From: <>
    | > | > | 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: <>
    | > | > | 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 Cheng[MSFT], Dec 19, 2005
    #6
  7. Guest

    Guest Guest

    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]" <> wrote in message
    news:IgU$...
    > 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: <>
    > | From: <>
    > | References: <>
    > <>
    > <>
    > <>
    > | 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$>
    > | 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]" <> wrote in message
    > | news:...
    > | > 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: <>
    > | > | From: <>
    > | > | References: <>
    > | > <>
    > | > | 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: <>
    > | > | 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]" <> wrote in message
    > | > | news:...
    > | > | > 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: <>
    > | > | > | From: <>
    > | > | > | 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: <>
    > | > | > | 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
    > | > | > |
    > | > | > |
    > | > | > |
    > | > | >
    > | > |
    > | > |
    > | > |
    > | >
    > |
    > |
    > |
    >
     
    Guest, Dec 21, 2005
    #7
  8. 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: <>
    | From: <>
    | References: <>
    <>
    <>
    <>
    <u$>
    <IgU$>
    | 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: <>
    | 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: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]" <> wrote in message
    | news:IgU$...
    | > 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: <>
    | > | From: <>
    | > | References: <>
    | > <>
    | > <>
    | > <>
    | > | 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$>
    | > | 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]" <> wrote in message
    | > | news:...
    | > | > 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: <>
    | > | > | From: <>
    | > | > | References: <>
    | > | > <>
    | > | > | 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: <>
    | > | > | 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]" <> wrote in
    message
    | > | > | news:...
    | > | > | > 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: <>
    | > | > | > | From: <>
    | > | > | > | 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: <>
    | > | > | > | 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 Cheng[MSFT], Dec 22, 2005
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. DC Gringo
    Replies:
    4
    Views:
    4,849
    mfreidge
    Dec 17, 2007
  2. nail
    Replies:
    0
    Views:
    1,564
  3. Guest
    Replies:
    5
    Views:
    433
    Scott David Daniels
    Mar 30, 2007
  4. Sergio E.

    get data that fills gridview inside the gridview

    Sergio E., Aug 8, 2007, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    232
    Sergio E.
    Aug 8, 2007
  5. Paul S
    Replies:
    9
    Views:
    1,068
    Steven Cheng [MSFT]
    Apr 18, 2008
Loading...

Share This Page