Click here to Skip to main content
15,891,657 members
Articles / Web Development / ASP.NET

Implementation of paging and sorting for the GridView control that works with an array of objects

Rate me:
Please Sign up or sign in to vote.
4.20/5 (14 votes)
16 Mar 20072 min read 103.2K   655   45  
The article describes how to implement paging and sorting for the GridView control that works with an array of objects.
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page 
{
    #region Event Handlers

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
            gv.BindDataSource();

    }
    protected void gv_DataSourceRequested(out Array dataSource)
    {
        dataSource = GetTestData();
    }

    #endregion

    #region Private

    private ProductInfo[] GetTestData()
    {
        ProductInfo[] res = new ProductInfo[8];
        res[0] = new ProductInfo("TV-Tuner", 1, 40.00);
        res[1] = new ProductInfo("Modem", 2, 19.00);
        res[2] = new ProductInfo("Motherbord", 1, 120.00);
        res[3] = new ProductInfo("Keyboard", 18, 5.00);
        res[4] = new ProductInfo("Mouse", 25, 4.99);
        res[5] = new ProductInfo("Mouse pad", 30, 1.50);
        res[6] = new ProductInfo("Monitor", 4, 234.00);
        res[7] = new ProductInfo("Fan", 10, 8.00);
        return res;
    }

    #endregion
}

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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Software Developer (Senior)
Ukraine Ukraine
I'm a software developer from Ukraine. I write about ASP.NET and other .NET related topics over at my blog

Comments and Discussions