Click here to Skip to main content
14,027,303 members
Click here to Skip to main content
Add your own
alternative version


22 bookmarked
Posted 25 Jan 2010
Licenced CPOL

Generic grid search and data paging

, 25 Jan 2010
Rate this:
Please Sign up or sign in to vote.
Generic grid search and data paging explained.



This article describes the DataFinder (user control) which proved to be very useful to me.


  • Problem, usually presents the following requirements:
    • Create a page for displaying a list of records from a SQL query.
    • Enable paging of the grid, where if you get 1000000 records, and all this information through the network (in case the database is not on the same server as the applications), then this information is loaded on the memory of the server application where it is filtered for the records that we really want to see (the current page). All this causes bad performance, but surely, many of us already have applications running this way.
    • Finally, or as they say "Adding the cherry on the cake", add a generic search feature to this grid.
  • Analysis. For the solution, we have to:
    • Create our SQL query in a Stored Procedure.
    • Add code to get data from the query.
    • Create a GridView control and customize the columns to receive the data.
    • Improve our Stored Procedure to add parameters using which we send page info for the data in the database.
    • Finally, we need to add more functionality to our Stored Procedure to receive parameters to send our search criteria.
  • Solution. Everything listed in the two previous points can be done, but would take considerable time and will become a repetitive task evolving according to the system. This is where the user control DataFinder proves helpful. This control simplifies all our work, and further enhances our performance (performes paging in the database).

Using the Code

You need to download the solution accompanying this article, which has the search code and an example of how to use it.

  • Open the solution, and the search engine is in the Controles folder. Images and CSS used by this control are in the CSS/Buscador folder (try to keep the structure of files as found in the example, so you won't have to change the style sheet and paths of the images for the User Control).
  • In the web.config, we have the CNN link chain that connects the database "AdventureWorks". You can download this database from: AdventureWorks. It is important to mention here that I connect to a SQL Server 2008 database.
  • Create your SQL query and store it in the folder "Consultas" in the same folder that has the "Ejemplo.sql" file (the file does not necessarily have the .sql extension) with the suggested format. The identifier "- $TART -" is the delimiter to indicate where the query begins, and what you have before you is a comment.
  • --------------------------------------------
    -- Name: Kevin Guisbert Segales
    -- Company: KDev
    -- Date: 13/01/2010
    -- Copyright 2010
    -- La Paz - Bolivia
    -- $TART --
    SELECT  e.EmployeeID,
    FROM    HumanResources.Employee e
  • Create an ASPX page. In this example, we have the page "Default.aspx" where you have to add the following file header attribute:
  • EnableEventValidation="false"
  • In the Head section, add the reference to the stylesheet of the page:
  • <link href="CSS/Buscador/Buscador.css" rel="stylesheet" type="text/css" />
  • Drag the user control "Buscador.ascx" to your page.
  • In the code-behind, add the following properties:
  • Protected Sub Page_Load(ByVal sender As Object, _
                  ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            '- Inicializamos datos del buscador -
            Me.Buscador1.Consulta = "Ejemplo.sql"
            Me.Buscador1.Titulo = "Buscador Genérico"
            Me.Buscador1.OrderBy = "Title"
        End If
    End Sub


    • Consulta is the name of the file containing the query and is placed in "Consultas" folder (required).
    • Titulo is the title to show in the control (optional).
    • OrderBy is the name of the field by which to order the query (required).
    • DataBind() is the method to proceed with the binding (required).
  • If you have followed the steps above, you can proceed to run your application and enjoy the control.

I hope this control will be useful. I will soon be enhancing this control.

Points of Interest

This application was tested using:

  • Windows XP SP3
  • Internet Explorer 6
  • Visual Studio 2008
  • SQL Server 2008


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer (Senior) RoadSight
Bolivia Bolivia
No Biography provided

You may also be interested in...

Comments and Discussions

GeneralNice control Pin
Member 414767415-Sep-16 20:57
memberMember 414767415-Sep-16 20:57 
GeneralMy vote of 5 Pin
Manoj Kumar Choubey10-Aug-12 2:24
professionalManoj Kumar Choubey10-Aug-12 2:24 
GeneralGracias! Pin
Member 77356878-Mar-11 3:48
memberMember 77356878-Mar-11 3:48 
Generalanother better approach Pin
vrajaraman1-Feb-10 15:44
membervrajaraman1-Feb-10 15:44 
QuestionWhere do they say "Adding the cherry on the cake"? Pin
Dankarmy30-Jan-10 10:24
memberDankarmy30-Jan-10 10:24 
GeneralNice control Pin
Brian Shifrin27-Jan-10 12:37
memberBrian Shifrin27-Jan-10 12:37 
Generalsource code Pin
michal.pristas25-Jan-10 9:28
membermichal.pristas25-Jan-10 9:28 
GeneralRe: source code Pin
Shane Story27-Jan-10 6:43
memberShane Story27-Jan-10 6:43 
GeneralMore info please Pin
spoodygoon25-Jan-10 7:45
memberspoodygoon25-Jan-10 7:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web01 | 2.8.190419.4 | Last Updated 25 Jan 2010
Article Copyright 2010 by KevGUID
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid