用gridview排序的时候,在.NET里是不能被标注的,下面提供如下方法:主要是显示的时候进行了下判断,然后进行不同的排序,这样就给这个gridview加上了排序的箭头,有意思的是<font face='Webdings'>个样式,如果你对<font face='Webdings'>不是很了解,下面是提供的连接:

http://www.cnblogs.com/freeton/archive/2009/06/27/1512139.html

注意:

Aspx页面:

设置排序:SortExpression="zhiwei"(给相应的字段设置)

.cs

开始设置的默认的排序状态用ViewState进行设置,写在!IsPostBack下面。

主要用到:GVpositionrecods_RowCreated与GVpositionrecods_Sorting事件

页面
代码

<asp:GridView AllowSorting="True" ID="GVpositionrecods" runat="server" PageSize="12"
                    AllowPaging="True" EmptyDataText="没有任何数据可以显示" Width="99%" AutoGenerateColumns="False"
                    OnRowDataBound="GVpositionrecods_RowDataBound" OnSelectedIndexChanged="GVpositionrecods_SelectedIndexChanged"
                    OnSelectedIndexChanging="GVpositionrecods_SelectedIndexChanging" OnPageIndexChanging="GVpositionrecods_PageIndexChanging"
                    OnRowCreated="GVpositionrecods_RowCreated" OnSorting="GVpositionrecods_Sorting">
                    <Columns>
                        <asp:TemplateField HeaderText="职位" SortExpression="zhiwei">
                            <ItemTemplate>
                                <a href='throwseeen2.aspx?qiyeid=<%#Eval("qiyeid")%>&id=<%#Eval("ORDER_FORM_ID") %>'>
                                    <%#Eval("zhiwei") %>
                                </a>
                            </ItemTemplate>
                            <ItemStyle HorizontalAlign="Center" />
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="企业名称" SortExpression="qiyeid">
                            <ItemTemplate>
                                <a href='seeenlist.aspx?getidforen=<%#Eval("qiyeid")%>'>
                                    <%#Eval("qiye")%>
                                </a>
                            </ItemTemplate>
                            <ItemStyle HorizontalAlign="Center" />
                        </asp:TemplateField>
                        <asp:BoundField DataField="COUNT" HeaderText="人数" SortExpression="COUNT">
                            <ItemStyle HorizontalAlign="Center" />
                        </asp:BoundField>
                        <asp:BoundField DataField="STAR_TIME" SortExpression="STAR_TIME" HeaderText="发布时间"
                            DataFormatString="{0:yyyy-MM-dd}" HtmlEncode="False">
                            <ItemStyle HorizontalAlign="Center" />
                        </asp:BoundField>
                        <asp:BoundField DataField="END_TIME" SortExpression="END_TIME" HeaderText="结束时间"
                            DataFormatString="{0:yyyy-MM-dd}" HtmlEncode="False">
                            <ItemStyle HorizontalAlign="Center" />
                        </asp:BoundField>
                        <asp:BoundField DataField="flag" HeaderText="状态">
                            <ItemStyle HorizontalAlign="Center" />
                        </asp:BoundField>
                    </Columns>
                    <AlternatingRowStyle BackColor="#E2F8FF"></AlternatingRowStyle>
                    <HeaderStyle HorizontalAlign="Center" BackColor="#99CCFF"></HeaderStyle>
                    <PagerStyle CssClass="cssPager" />
                </asp:GridView>

默认排序设置

代码

 protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["student"] == null)
        {
            Response.Write("<script>alert('页面已过期,请重新登录!');window.parent.frames.location.href='../Default.aspx'</script>");
        }
        else if (!IsPostBack && Session["t_resume_info"] != null)
        {
            ViewState["sortExp"] = "STAR_TIME";//默认排序的字段
            ViewState["sortDir"] = "Desc";// 字段是安什么排序的
            //绑定数据源
            bind();

this.lbcontent.Visible = false;
        }
        else if (Session["t_resume_info"] == null)
        {
            this.lbcontent.Text = "您还没有任何录取的信息";
        }
    }

绑定的数据源

代码

public void bind()
    {
        //得到对应的简历的ID,从SN里面查看值
        ccwu.Model.T_RESUME_INFO listTemp = (ccwu.Model.T_RESUME_INFO)Session["t_resume_info"];
        ccwu.Model.T_ORDER_RESUME torderresume = new ccwu.Model.T_ORDER_RESUME();
        int id = Convert.ToInt32(listTemp.ID.ToString());
        //得到对应的简历的ID,从SN里面查看值

ccwu.DAL.T_JOB jobdal = new ccwu.DAL.T_JOB();
        string where = "RESUME_INFO_ID='" + id.ToString() + "'";

DataSet ds = jobdal.getlistResume(where);
        DataView dv = new DataView(ds.Tables[0]);
        dv.Sort = ViewState["sortExp"].ToString() + " " + ViewState["sortDir"].ToString();
        GVpositionrecods.DataSource = dv;
        this.GVpositionrecods.DataBind();
        if (this.GVpositionrecods.Rows.Count > 0)
        {

}
        else//如果数据源是空的
        {
            //表头的设置
            GridViewRow row = new GridViewRow(-1, -1, DataControlRowType.EmptyDataRow, DataControlRowState.Normal);
            foreach (DataControlField field in this.GVpositionrecods.Columns)
            {
                TableCell cell = new TableCell();
                cell.Text = field.HeaderText;
                cell.Width = field.HeaderStyle.Width;
                cell.Height = field.HeaderStyle.Height;
                cell.ForeColor = field.HeaderStyle.ForeColor;
                cell.Font.Size = field.HeaderStyle.Font.Size;
                cell.Font.Bold = field.HeaderStyle.Font.Bold;
                cell.Font.Name = field.HeaderStyle.Font.Name;
                cell.Font.Strikeout = field.HeaderStyle.Font.Strikeout;
                cell.Font.Underline = field.HeaderStyle.Font.Underline;
                cell.BackColor = field.HeaderStyle.BackColor;
                cell.VerticalAlign = field.HeaderStyle.VerticalAlign;
                cell.HorizontalAlign = field.HeaderStyle.HorizontalAlign;
                cell.CssClass = field.HeaderStyle.CssClass;
                cell.BorderColor = field.HeaderStyle.BorderColor;
                cell.BorderStyle = field.HeaderStyle.BorderStyle;
                cell.BorderWidth = field.HeaderStyle.BorderWidth;
                row.Cells.Add(cell);
            }
            TableItemStyle headStyle = this.GVpositionrecods.HeaderStyle;
            TableItemStyle emptyStyle = GVpositionrecods.EmptyDataRowStyle;
            emptyStyle.Width = headStyle.Width;
            emptyStyle.Height = headStyle.Height;
            emptyStyle.ForeColor = headStyle.ForeColor;
            emptyStyle.Font.Size = headStyle.Font.Size;
            emptyStyle.Font.Bold = headStyle.Font.Bold;
            emptyStyle.Font.Name = headStyle.Font.Name;
            emptyStyle.Font.Strikeout = headStyle.Font.Strikeout;
            emptyStyle.Font.Underline = headStyle.Font.Underline;
            emptyStyle.BackColor = headStyle.BackColor;
            emptyStyle.VerticalAlign = headStyle.VerticalAlign;
            emptyStyle.HorizontalAlign = headStyle.HorizontalAlign;
            emptyStyle.CssClass = headStyle.CssClass;
            emptyStyle.BorderColor = headStyle.BorderColor;
            emptyStyle.BorderStyle = headStyle.BorderStyle;
            emptyStyle.BorderWidth = headStyle.BorderWidth;
            //空白行的设置
            GridViewRow row1 = new GridViewRow(0, -1, DataControlRowType.EmptyDataRow, DataControlRowState.Normal);

TableCell cell1 = new TableCell();
            cell1.Text = "没有任何数据可以显示";
            cell1.BackColor = System.Drawing.Color.White;
            row1.Cells.Add(cell1);
            cell1.ColumnSpan = 6;//合并列

if (this.GVpositionrecods.Controls.Count == 0)
            {
                GVpositionrecods.Page.Response.Write("<script language='javascript'>alert('必须在初始化表格类之前执行DataBind方法并设置EmptyDataText属性不为空!');</script>");
            }
            else
            {
                GVpositionrecods.Controls[0].Controls.Clear();
                this.GVpositionrecods.Controls[0].Controls.AddAt(0, row);
                this.GVpositionrecods.Controls[0].Controls.AddAt(1, row1);
            }
        }

}

关键代码

代码

 protected void GVpositionrecods_RowCreated(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.Header)//如果是表头,则执行如下操作
        {
            foreach (TableCell tc in e.Row.Cells)
            {
                //这种方法直接新加一个控件,也可以换成图片               
                if (tc.Controls.Count > 0)//这里要判断一下此时是不是已经生成了linkbutton
                {
                    string s1 = ((LinkButton)tc.Controls[0]).Text;
                    //样式Webdings是123都有自己对应的图片
                    ((LinkButton)tc.Controls[0]).Text = s1.Replace(s1, s1 + "<font face='Webdings'>5</font>");
                    //倒序的样式
                    if (tc.Controls.Count > 0 && tc.Controls[0].GetType().ToString() == "System.Web.UI.WebControls.DataControlLinkButton")
                    {
                        if (((LinkButton)tc.Controls[0]).CommandArgument.ToString() == ViewState["sortExp"].ToString())
                        {
                            string s2 = ((LinkButton)tc.Controls[0]).Text;
                            if (ViewState["sortDir"].ToString() == "Desc")
                            {
                                ((LinkButton)tc.Controls[0]).Text = s2.Replace("5", "6");
                            }
                        }
                    }
                }
            }
        }
    }

当点击列头的时候

代码

protected void GVpositionrecods_Sorting(object sender, GridViewSortEventArgs e)
    {
        string sPage = e.SortExpression;

if (ViewState["sortExp"].ToString() == sPage)
        {
            if (ViewState["sortDir"].ToString() == "Desc")
                ViewState["sortDir"] = "ASC";
            else
                ViewState["sortDir"] = "Desc";
        }
        else
        {
            ViewState["sortExp"] = e.SortExpression;
        }
        bind();
    }

转载于:https://www.cnblogs.com/muer/archive/2010/03/26/1697213.html

gridview排序加箭头(二)相关推荐

  1. [OHIF-Viewers]医疗数字阅片-医学影像-中间插播一下-es6-使用const加箭头函数声明函数相对于function声明函数有什么好处?...

    [OHIF-Viewers]医疗数字阅片-医学影像-中间插播一下-es6-使用const加箭头函数声明函数相对于function声明函数有什么好处? 这个好多人都已经写过了,这里插播一下,在OHIF- ...

  2. HDU1106 排序(解法二)(废除!!!)

    本文废除!!! 请点击以下的参考链接!!! 参考链接:HDU1106 排序[字符串+整数+排序]. 问题链接:HDU1106 排序. 问题简述:参见上述链接. 问题分析:这个程序的逻辑并不十分复杂,主 ...

  3. mysql日期排序YMD_php将二维数组按日期(支持Ymd和Ynj格式日期)排序

    思路: 将所有日期转化成时间戳保存在新数组里面(新数组1和新数组2), 将新数组2排序, 再将新数组2中的元素逐个查找在数组1中的索引, 根据索引将原始数组重新排序, 最终得到排序后的二维数组. - ...

  4. 基于Vue框架开发的页面加载二维地图以及交互

    一.在Vue项目中引入二维地图 1.切换到公司的仓库下载地图插件 npm config set registry http://nexus.toops.club/repository/npm-zui/ ...

  5. 图片加载 二维码 解析

    图片加载 二维码 解析 1. layout布局文件 (1)activity_category.xml <?xml version="1.0" encoding="u ...

  6. 赛效:使用视频剪辑工具秀多多怎么在视频中加箭头?

    在制作视频时,为了使视频更加的直观,在视频播放过程中,可以给视频的某些部位添加一些箭头指针符号,来着重引起观看者的关注,如何在视频中加箭头符号呢?下面我们以秀多多视频剪辑工具给大家演示下添加的视频怎么 ...

  7. 从无人货架到无人售货柜,加了二维码就叫“新零售”吗?

    近日,京东到家宣布,其新一代智能货柜--京东到家Go已正式对外运营.预计年底前京东到家Go将会覆盖包括北上广深在内的全国10个以上主要城市.随着京东到家Go的入局,国内无人售货柜市场已经聚集了众多巨头 ...

  8. android加载二维码带中间logo

    android加载二维码带中间logo 很简单的,我也是先看了很多博客,然后总结了一下,感谢万能的网友 1导入依赖 //二维码加载依赖 implementation 'com.google.zxing ...

  9. asp.net中GridView排序的手动实现

    GridView自带了数据排序功能.在设计视图下,只能对GridView的排序数据列和排序方向进行静态设置.如果要自己实现排序功能,在后台程序中,则需要用Attributes方式对GridView的这 ...

最新文章

  1. 【面试题】hashCode() 和 equals() 之间的关系
  2. 【机器学习基础】Python实现行转列?!超简单,赶快get起来
  3. Linux内核态抢占机制分析
  4. 我为什么fuck GFW同时FUCK 开心网
  5. eclipse发布rest_在Eclipse中高效运行HTTP / REST集成测试
  6. 使用RequestFactory API进行Spring GWT集成
  7. react 日历组件_anujs1.5.1支持React.Suspense与lazy
  8. tcpdump 抓二层包_可能是我见过的最简单易懂且实用的 TCPDump 和 Wireshark 抓包及分析教程!( 强烈建议收藏 )...
  9. 小程序 按需_小程序想要留住用户需哪些举措?
  10. linux上git克隆命令,Git clone命令用法
  11. 计算机操作基础英语,计算机操作基础word练习题参考答案
  12. 关闭网页如何接收服务器消息,WebSocket服务端发消息给客户端,浏览器收到消息就关闭了...
  13. 一加10 Pro首发定制X轴线性马达:Top级超大体积 安卓阵营马达天花板
  14. PAT甲级1004 (DFS,树的父子节点)
  15. 容易遗忘的JS知识点整理
  16. 20172330 2017-2018-2 《程序设计与数据结构》实验一报告
  17. 二级 c语言真题及答案,3月计算机二级C语言真题及答案(完整版)
  18. 仓库管理系统论文+源程序+执行程序,
  19. 怎样添加图片到黑莓7290手机里?
  20. .reg注册表文件的编写

热门文章

  1. 《零基础》MySQL GROUP BY 语句(十九)
  2. sql server 2008表中计算机,电脑删除SQLsever2008表格数据出现“不能删除”怎么办
  3. linux dns中文域名,Linux 搭建中文域名的DNS服务器
  4. 计算机显示文本自定义130%,实训课题目
  5. Git clone的使用方法
  6. Spring Boot freemarker导出word下载
  7. js调用python接口_JavaScript如何调用Python后端服务
  8. C++ PAT 乙级 ——1002 读入一个正整数 n,计算其各位数字之和,用汉语拼音写出和的每一位数字。
  9. Python入门基础篇(五)字符串的正则表达式re模块,全面解析!!!
  10. cas登录成功后不跳转成功页面_SpringSecurity用户登录成功后页面跳转原理剖析