Click here to Skip to main content
15,892,005 members
Articles / Web Development / HTML

ASP.NET DataGrid Extension [Client Side Sortable/Dragable....] - Part I

Rate me:
Please Sign up or sign in to vote.
4.67/5 (22 votes)
28 Feb 2008CPOL5 min read 87.3K   1.8K   71  
An extension to the ASP.NET DataGrid control with built-in client side sorting, column dragging, fixed header, check all, uncheck all, highlight selected row, and more...
using System;
using System.Collections;
using System.Text;
using System.Web.UI.WebControls;

namespace CodeWorks
{
   
    public class ColumnComparer : IComparer
    {
        public ColumnComparer(string order)
        {
            ColumnsOrder = order.Split(',');
        }

        private string[] ColumnsOrder;
        int IComparer.Compare(object x, object y)
        {

            DataGridColumn dgcx = (DataGridColumn)x;
            int indexOfx = Array.IndexOf(ColumnsOrder, dgcx.HeaderText);

            DataGridColumn dgcy = (DataGridColumn)y;
            int indexOfy = Array.IndexOf(ColumnsOrder, dgcy.HeaderText);

            if (indexOfx < indexOfy)
                return -1;
            if (indexOfx == indexOfy)
                return 0;
            else
                return 1;
        }
    }

   
}

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 (Senior) Systems Limited
Pakistan Pakistan
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions