Table 里面点标题会进行排序

using System;
using System.Web;
using System.Collections;
using System.Collections.Generic;
public class AcSort
{
    private Object _currentSortType;
    public object CurrentSortType { get { return _currentSortType; } set { _currentSortType = value; } }
    //private String _currentSortType;
    //public short CurrentSortType { get { return _currentSortType; } set { _currentSortType = value; } }
    private int _currentSortDir; //0为升序  1为倒序
    public int CurrentSortDir { get { return _currentSortDir; } set { _currentSortDir = value; } }
    private int _defaultSortDir = 0;
    public int DefaultSortDir { get { return _defaultSortDir; } set { _defaultSortDir = value; } }
    private int _defaultSortType = 0;
    public int DefaultSortType { get { return _defaultSortType; } set { _defaultSortType = value; } }
    private string pageUrl;
    private string _baseImg = "../Theme/Images/";
    public string BaseImg { get { return _baseImg; } set { _baseImg = value; } }

    public AcSort()
    {
        string str = "";
        if (!string.IsNullOrEmpty(HttpContext.Current.Request.QueryString["sort"]))
        {
            str = HttpContext.Current.Request.Url.ToString();
            int l1 = str.IndexOf("sort");
            int l2 = str.IndexOf("&", l1 + 1);
            if (l2 > 0)
            {
                if (str.Length >= l2 + 1)
                    pageUrl = str.Substring(0, l1) + str.Substring(l2 + 1);
                else
                    pageUrl = str.Substring(0, l1);
            }
            else
            {
                pageUrl = str.Substring(0, l1 - 1);
            }
        }
        else
        {
            pageUrl = HttpContext.Current.Request.Url.ToString();
        }
        if (pageUrl.IndexOf("?") > 0)
            pageUrl = pageUrl + "&";
        else
            pageUrl = pageUrl + "?";
    }
    private string getImg(int SDir)
    {
        if (SDir == 0)
            return "<img src=\"" + _baseImg + "menudark_up.gif\" class=\"va_tb\" />";
        else
            return "<img src=\"" + _baseImg + "menudark_down.gif\" class=\"va_tb\" />";
    }
    public string GenerateSort(int col, string text)
    {
        string url = "<a href=\"{0}\" title=\"\">" + text + "</a>";
        short dir = 0;//升序
        if (col == Convert.ToInt16(_currentSortType))//
        {
            if (_currentSortDir == 0)
                dir = 1;
            else
                dir = 0;
            url = url + getImg(_currentSortDir);
        }
        return string.Format(url, pageUrl + "sort=" + dir + "," + col);
    }
    public string GenerateSort(String col, string text)
    {
        string url = "<a href=\"{0}\" title=\"\">" + text + "</a>";
        short dir = 0;//升序
        if (col == _currentSortType.ToString())//
        {
            if (_currentSortDir == 0)
                dir = 1;
            else
                dir = 0;
            url = url + getImg(_currentSortDir);
        }
        return string.Format(url, pageUrl + "sort=" + dir + "," + col);
    }
    /// <summary>
    /// 排序
    /// </summary>
    /// <param name="x"></param>
    /// <param name="y"></param>
    /// <returns></returns>
    public class myReverserClass : IComparer
    {
        int IComparer.Compare(Object x, Object y)
        {
            return ((new CaseInsensitiveComparer()).Compare(x, y));
        }
    }
}
原文地址:https://www.cnblogs.com/MySpace/p/1599818.html