Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 846249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T06:35:03+00:00 2026-05-15T06:35:03+00:00

I have a gridview that takes in values from a sortedlist. I want to

  • 0

I have a gridview that takes in values from a sortedlist. I want to filter those values before putting them in the gridview without taking values out of the list.

Is there an easy way to do this? Or do I have to redirect the data through another list and point the gridview to it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T06:35:04+00:00Added an answer on May 15, 2026 at 6:35 am

    There are probably a number of ways to do this, but none are magic. All involve some work.

    If the list is in memory, yes, you’ll have to wash the list through a filtering process before binding to the grid.

    If the list comes from a database, then you should be doing the filtering at the database level. The way I prefer to do this is by binding the grid to an ObjectDataSource. You can also bind other controls in the UI as select parameters in the ObjectDataSource. (You can also do sorting and paging through the ObjectDataSource, so that everything can be built in to your database query, and the grid binds only to the data you want to display.)

    Here’s an ObjectDataSource fully configured:

    <asp:ObjectDataSource ID="CustomerObjectDataSource" runat="server" 
        EnablePaging="True" 
        MaximumRowsParameterName="totalRows" 
        StartRowIndexParameterName="firstRow" 
        TypeName="Northwind.Business.CustomerSource" 
        DataObjectTypeName="Northwind.Business.CustomerDTO"
        SelectMethod="Load" 
        UpdateMethod="Save" 
        InsertMethod="Insert" 
        DeleteMethod="Delete"
        SelectCountMethod="CustomerCount" 
        SortParameterName="sortExpression">
        <SelectParameters>
            <asp:ControlParameter ControlID="ddlRegion" Name="region" 
                PropertyName="SelectedValue" />
        </SelectParameters>
    </asp:ObjectDataSource>    
    

    Note that it is binding to a dropdown list for selection in the database query.

    Here’s the grid, with binding:

    <asp:GridView ID="GridView1" runat="server" 
        AutoGenerateColumns="False" 
        DataSourceID="CustomerObjectDataSource" 
        DataKeyNames="CustomerID"
        AllowPaging="True" 
        AllowSorting="True" AutoGenerateDeleteButton="True" 
        AutoGenerateEditButton="True" AutoGenerateSelectButton="True" 
        onrowdeleted="GridView1_RowDeleted" onrowupdated="GridView1_RowUpdated">
        <Columns> .....
    

    Here’s the method the ObjectDataSource binds to for selection:

    public static List<CustomerDTO> Load(
        int totalRows, 
        int firstRow, 
        string sortExpression,
        string region)
    { ... }
    

    The Load method builds the query and runs it, then returns the data. It can be either an IEnumerable or List, as you see here, or a DataSet or DataTable. That should get you started.

    One nice thing is that the code-behind is almost empty now. It only needs to handle events that don’t relate to binding, sorting, or paging.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ListView (GridView) that I want to sort by 2 columns, so
I have a nested gridview with 45 checkboxes. I want the user to be
I use EF 4, C# and MS Membership Provider. I have a GridView with
I have a dynamic (allows addition of rows on the fly) an ASP gridview
I have a GridView which shows only 50 records at a time through paging.
I want to show some progress animation in my textbox. Becoz when i click
I am using Winforms for my application & SQL Server as database. I want
suppose i have many heavy control is on the page. as for example i
I have seen some other posts on how to get this working ... however
I am developing an ASP.NET where I need to display each purchase for every

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.