Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version
Go to top

Fast GridView

, 4 Nov 2008
A fast and optimized GridView.
Article_demo.zip
smartgridview with smartpager
App_Code
bin
SmartPagerIcon.bmp
using System;
using System.Text;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Data.OleDb;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Configuration;
using Avg.Controls;


//To test this code :
//1-download the AdventureWorks database  at http://www.microsoft.com/downloads/details.aspx?familyid=e719ecf7-9f46-4312-af89-6ad8702e4e6e&displaylang=en
//2-execute stored procedure on sql server :

//set ANSI_NULLS ON
//set QUOTED_IDENTIFIER ON
//go

//CREATE PROCEDURE [dbo].[ProductsByRows] 
//(@pBegin int,
// @pEnd int)
//AS
// With Prod AS 
//( SELECT [ProductID], 
//         [ProductName], 
//         [SupplierID], 
//         [CategoryID], 
//         [QuantityPerUnit], 
//         [UnitPrice], 
//         [UnitsInStock], 
//         [UnitsOnOrder], 
//         [ReorderLevel], 
//         [Discontinued] ,  
//         ROW_NUMBER() OVER (order by ProductName) as RowNumber from Products )
//         SELECT [ProductID], 
//        [ProductName], 
//        [SupplierID], 
//        [CategoryID], 
//        [QuantityPerUnit], 
//        [UnitPrice], 
//        [UnitsInStock], 
//        [UnitsOnOrder], 
//        [ReorderLevel], 
//        [Discontinued] from Prod  Where RowNumber 
//Between @pBegin and @pEnd 




public partial class _Default : System.Web.UI.Page
{


    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
    }
   
   
    protected void GrdMain_DoLoadRowCount(object sender, EventArgs e)
    {
        StringBuilder que = new StringBuilder();
        que.Append(" SELECT count([ProductID]) from Products ");


        SqlConnection con = new SqlConnection(
            System.Configuration.ConfigurationSettings.AppSettings["conx"]
            );

        con.Open();

        SqlCommand command = new SqlCommand(que.ToString(), con);
        command.CommandType = CommandType.Text;

        object val = command.ExecuteScalar();
        con.Close();

        GrdMain.RowCount = Int32.Parse(val.ToString());
    }
    
    protected void GrdMain_DoSelectRow(object sender, EventArgs e)
    {
        
            SqlConnection con = new SqlConnection(
                 System.Configuration.ConfigurationSettings.AppSettings["conx"]
                 );

            con.Open();

            SqlCommand command = new SqlCommand("ProductsByRows", con);
            command.CommandType = CommandType.StoredProcedure;

            command.Parameters.Add(new SqlParameter("@pBegin", GrdMain.rowB));
            command.Parameters.Add(new SqlParameter("@pEnd", GrdMain.rowE));

            DataSet prod = new DataSet();
            SqlDataAdapter adap = new SqlDataAdapter(command);
            adap.Fill(prod);

            con.Close();

            GrdMain.DataSource = prod.Tables[0];
            DataBind();

        
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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

Share

About the Author

David Zenou
Software Developer Several
France France
I am a Fan of dotnet technologies. I began to work with Java j2ee technologies and today i made my choice : .Net Framework is very pleasant , has excellents article codes and documentation.
I found very useful articles in codeproject , and today i want to give my contribution , and i hope that my articles will be useful.
 
Go to see my blog : http://davidzenou.blogspot.com/2009/01/david.html

| Advertise | Privacy | Mobile
Web01 | 2.8.140916.1 | Last Updated 4 Nov 2008
Article Copyright 2008 by David Zenou
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid