向gridview标题头中添加排序图片,当点击某一个头标题时,在标题中出现升序箭头向上的图片,再点击一次时降序,在标题中出现箭头向下的图片,初始页面时在标题头中并不现实任何图片。

先定义好一个gridview,在gridview数据绑定结束后调下面方法。

protected void SortForImage(string sortDirection, string sortExpression)
{
if (!string.IsNullOrEmpty(sortExpression))
{
GridViewRow headRow = gvPlanedTools.HeaderRow;
Image sortImage = new Image();
if (sortDirection == "ASC")
{
sortImage.ImageUrl = "~/_layouts/1033/IMAGES/WebPartImages/bullet_arrow_down.png";
sortImage.Style.Add("vertical-align", "bottom");
}
else
{
sortImage.ImageUrl = "~/_layouts/1033/IMAGES/WebPartImages/bullet_arrow_up.png";
sortImage.Style.Add("vertical-align", "bottom");
}
int num = ;
foreach (DataControlField field in gvPlanedTools.Columns)
{
if (field.SortExpression == sortExpression.ToString().Trim())
{
num = gvPlanedTools.Columns.IndexOf(field);
}
}
headRow.Cells[num].Controls.Add(sortImage);
}
}

另外在gridview sorting 方法中也需调用此方法,这里是在BindView()方法中调用上面添加图片排序的方法, 如:

protected void gvPlanedTools_Sorting(object sender, GridViewSortEventArgs e)
{
string sortExpression = e.SortExpression.ToString();
string sortDirection = "ASC";
if (sortExpression == gvPlanedTools.Attributes["SortExpression"])
{
sortDirection = (gvPlanedTools.Attributes["SortDirection"].ToString() == sortDirection ? "DESC" : "ASC");
}
gvPlanedTools.Attributes["SortExpression"] = sortExpression;
gvPlanedTools.Attributes["SortDirection"] = sortDirection;
BindView();
}

BindView细节如下:

 private void BindView()
{
DataSet ds = GetDataSet();
if (IsDateSetNullOREmpty(ds))
{
DataTable dt = ds.Tables[];
ViewState["PageCount"] = dt.Rows.Count.ToString();
string sortExpression = gvPlanedTools.Attributes["SortExpression"];
string sortDirection = gvPlanedTools.Attributes["SortDirection"];
if ((!string.IsNullOrEmpty(sortExpression)) && (!string.IsNullOrEmpty(sortDirection)))
{
dt.DefaultView.Sort = string.Format("{0} {1}", sortExpression, sortDirection);
}
gvPlanedTools.DataSource = dt.DefaultView;
gvPlanedTools.DataBind();
SortForImage(gvPlanedTools.Attributes["SortDirection"], gvPlanedTools.Attributes["SortExpression"]);
}
}

Gridview标题头添加排序图片的更多相关文章

  1. AdvStringGrid 点击标题头 自动排序

  2. [Android] 通过GridView仿微信动态添加本地图片

    原文:http://blog.csdn.net/eastmount/article/details/41808179 前面文章讲述的都是"随手拍"中图像处理的操作,此篇文章主要讲述 ...

  3. 详解ASP.NET4 GridView的四种排序样式

    与ASP.NET 的其他Web控件一能够,Gridview控件拥有很多不同的CSS样式属性设置,包括象CssClass,Font字体,ForeColor,BackColor,BackColor, Wi ...

  4. C# listview 单击列头实现排序 <二>

    单击列头实现排序,首先在羡慕中添加下面的帮助实现的类:具体的代码: using System; using System.Collections; using System.Windows.Forms ...

  5. C#:ListView控件如何实现点击列表头进行排序?

    using System; using System.Collections; using System.Windows.Forms; namespace Common { /// <summa ...

  6. 利用LruCache为GridView加载大量本地图片完整示例

    MainActivity如下: package cc.testlrucache; import android.os.Bundle; import android.widget.GridView; i ...

  7. ClistCtrl用法及总结(由怎样隐藏ListCtrl列表头的排序小三角形这个bug学习到的知识)

    1 怎样隐藏ListCtrl列表头的排序小三角形 在创建控件是加入|LVS_NOSORTHEADER风格即可. 一下是用法总结: 本文根据本人在项目中的应用,来谈谈CListCtrl的部分用法及技巧. ...

  8. 给织梦DEDECMS添加栏目图片与英文名显示

    开始做微网站了,不同于传统手机网站,因为微信上的微网站是支持CSS3与HTML5的,好吧,各种要学习的还有很多很多阿~这么多新代码,叹! 本来想转战帝国CMS了,奈何这名字太不对味了,PHPCMS也懒 ...

  9. 网站添加logo图片

    网站添加log图片 第一种方法 这里使用的图片一般为16*16大小的图片 <link rel="shortcut icon" href="http://xxx.xx ...

随机推荐

  1. 免登陆下载jdk

    linux下使用wget免登陆获取jdk对应版本gz包 wget --no-check-certificate --no-cookies --header "Cookie: oracleli ...

  2. Oracle查询重复数据并删除,只保留一条记录

    前言 项目中,在“资源目录-在线编目”中,资源项子表存在多条重发数据,需要进行数据清理,删除重发的数据,最终只保留一条相同的数据. 操作的表名:R_RESOURCE_DETAILS 操作步骤 一.重复 ...

  3. 学习MySQL过程中的随笔一

    第一天: 关于安装出现了很多问题,各种不懂的bug,没得法只能在网上查找解决方法,终于!!! 登录成功了,一下午的时间 附上参考资料:https://blog.csdn.net/weibo_boer/ ...

  4. css实现礼券效果3

    <view class="coupon"> <view class="coupon-left"> </view> <v ...

  5. 时间、日历(time、calendar、datatime)

    import time import calendar import datatime #获取代码运行的时间差 start = time.time() end = time.time() print( ...

  6. html-webpack-plugin插件使用时参数配置

    ERROR in multi main Module not found: Error: Cannot resolve 'file' or 'directory' ./public/pages/ind ...

  7. phpstorm----------phpstorm如何安装和使用laravel plugin

    1.安装 2.安装成功以后,删除项目里面的.idea文件.然后关闭phpstrom,重新打开该项目,就会提示你 然后.idea里面就会生成 laravel-plugin.xml 文件.就可以使用直接C ...

  8. Jenkins - ERROR: Exception when publishing, exception message [Failure] Build step 'Send build artifacts over SSH' changed build result to UNSTABLE

    今天在处理Jenkins的时候出现了一些异常,看着控制台,编译都是通过的,只是没有部署上来,查看了控制台日志,如下: 刚开始还以为是权限通道什么的,后来才发现是执行脚本根本不让执行,以前也遇到过,都是 ...

  9. nodejs:导出Excel和解析导入的Excel

    用的是koa2框架,但好好处理一下,用express框架也是可以的.导出的Excel是xlsx的格式,解析导入Excel的有xlsx和csv格式.通常导入Excel是要上传的,然后获取文件的路径,这里 ...

  10. UVA10723 电子人的基因 Cyborg Genes

    题意翻译 [题目描述] 输入两个A~Z组成的字符串(长度均不超过30),找一个最短的串,使得输入的两个串均是它的子序列(不一定连续出现).你的程序还应统计长度最短的串的个数. e.g.:ABAAXGF ...