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

Sortable GridView using jQuery's TableSorter

Rate me:
Please Sign up or sign in to vote.
4.82/5 (12 votes)
8 Oct 2008CPOL3 min read 131.6K   5K   63  
A client-side sortable GridView using jQuery's plugin table sorter.
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            this.gvEmployees.DataBind();
        }
    }

    protected void odsEmployee_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
    {
        e.InputParameters["connectionString"] = ConfigurationManager.ConnectionStrings["AdventureWorksConnectionString"].ConnectionString;
        e.InputParameters["PageNumber"] = this.hfPageNumber.Value;
    }

    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        if (Convert.ToInt32(this.hfPageNumber.Value) <= 20)
        {
            this.hfPageNumber.Value = (Convert.ToInt32(this.hfPageNumber.Value) + 1).ToString();
        }
        else
        {
            this.hfPageNumber.Value = "1";
        }
        this.gvEmployees.DataBind();
    }

    protected void gvEmployees_DataBound(object sender, EventArgs e)
    {
        if (this.gvEmployees.Rows.Count > 0)
        {
            gvEmployees.UseAccessibleHeader = true;
            gvEmployees.HeaderRow.TableSection = TableRowSection.TableHeader;
            gvEmployees.FooterRow.TableSection = TableRowSection.TableFooter;
        }
    }

    protected void LinkButton2_Click(object sender, EventArgs e)
    {
        this.hfPageNumber.Value = "1";
        this.hfIsDebug.Value = this.CheckBoxList1.Items[0].Selected.ToString().ToLower();
        this.hfInitialSortByColumnIndex.Value = this.DropDownList1.SelectedValue;        
        this.gvEmployees.CssClass = this.RadioButtonList1.SelectedValue;
        this.gvEmployees.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)


Written By
Software Developer GMS Ltd.
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions