惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
G
Google Developers Blog
L
LangChain Blog
Y
Y Combinator Blog
Vercel News
Vercel News
WordPress大学
WordPress大学
大猫的无限游戏
大猫的无限游戏
博客园 - Franky
V
Visual Studio Blog
小众软件
小众软件
月光博客
月光博客
A
About on SuperTechFans
H
Hackread – Cybersecurity News, Data Breaches, AI and More
T
The Blog of Author Tim Ferriss
有赞技术团队
有赞技术团队
M
MIT News - Artificial intelligence
阮一峰的网络日志
阮一峰的网络日志
Last Week in AI
Last Week in AI
博客园 - 【当耐特】
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
MongoDB | Blog
MongoDB | Blog
Jina AI
Jina AI
美团技术团队
量子位

博客园 - myer

使用you-get下载youtube视频 找不到org.springframework.context.ConfigurableApplicationContext的类文件 Centos7安装mysql8 无法加载oramts.dll 反射应用中的同种类型转换错误 - myer - 博客园 aspx文件生产静态html文件 在ASP.NET中实现Url Rewriting 正则表达式 c# 手机号码正则表达式 - myer - 博客园 jscalendar-1.0中文解决方法 GridView中嵌套GridView asp.net 小偷程序实现的原理和源码 - myer - 博客园 开源软件FtpClient几个问题 CMM简介 C# ping命令的实现 DIV模式窗口的实现 .net中序列化和反序列化 ASP.net 本地化和国际化 C#编码规范
GridView 排序
myer · 2007-03-28 · via 博客园 - myer

GridView 排序时只能按照一种方式排序 及e.SortDirection始终为"Ascending",下面是自己做的一点修改
保存视图状态:
/// <summary>
    /// 保存排序顺序
    /// </summary>
    public SortDirection GridViewSortDirection
    {
        get
        {
            if (ViewState["sortDirection"] == null)
                ViewState["sortDirection"] = SortDirection.Ascending;
            return (SortDirection)ViewState["sortDirection"];
        }
        set { ViewState["sortDirection"] = value; }
    }
GridView的排序事件:
protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
    {
        string sortExpression = e.SortExpression;
        try
        {
            DataView dv = 得到数据集;
            if (GridViewSortDirection == SortDirection.Ascending)
            {
                GridViewSortDirection = SortDirection.Descending;
                dv.Sort = sortExpression + " desc";               
            }
            else
            {
                GridViewSortDirection = SortDirection.Ascending;
                dv.Sort = sortExpression + " asc";               
            }
            GridView1.DataSource = dv;
            GridView1.DataBind();
        }
        catch
        {
           
        }
    }

posted on 2007-03-28 09:17  myer  阅读(573)  评论()    收藏  举报