Gridview标题头添加排序图片
向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标题头添加排序图片的更多相关文章
- AdvStringGrid 点击标题头 自动排序
- [Android] 通过GridView仿微信动态添加本地图片
原文:http://blog.csdn.net/eastmount/article/details/41808179 前面文章讲述的都是"随手拍"中图像处理的操作,此篇文章主要讲述 ...
- 详解ASP.NET4 GridView的四种排序样式
与ASP.NET 的其他Web控件一能够,Gridview控件拥有很多不同的CSS样式属性设置,包括象CssClass,Font字体,ForeColor,BackColor,BackColor, Wi ...
- C# listview 单击列头实现排序 <二>
单击列头实现排序,首先在羡慕中添加下面的帮助实现的类:具体的代码: using System; using System.Collections; using System.Windows.Forms ...
- C#:ListView控件如何实现点击列表头进行排序?
using System; using System.Collections; using System.Windows.Forms; namespace Common { /// <summa ...
- 利用LruCache为GridView加载大量本地图片完整示例
MainActivity如下: package cc.testlrucache; import android.os.Bundle; import android.widget.GridView; i ...
- ClistCtrl用法及总结(由怎样隐藏ListCtrl列表头的排序小三角形这个bug学习到的知识)
1 怎样隐藏ListCtrl列表头的排序小三角形 在创建控件是加入|LVS_NOSORTHEADER风格即可. 一下是用法总结: 本文根据本人在项目中的应用,来谈谈CListCtrl的部分用法及技巧. ...
- 给织梦DEDECMS添加栏目图片与英文名显示
开始做微网站了,不同于传统手机网站,因为微信上的微网站是支持CSS3与HTML5的,好吧,各种要学习的还有很多很多阿~这么多新代码,叹! 本来想转战帝国CMS了,奈何这名字太不对味了,PHPCMS也懒 ...
- 网站添加logo图片
网站添加log图片 第一种方法 这里使用的图片一般为16*16大小的图片 <link rel="shortcut icon" href="http://xxx.xx ...
随机推荐
- match 和 lastIndex 字符串检测差异
match .replace .search 这写不能识别特殊字符 indexOf .indexof 能识别特殊字符 str.lastIndexOf('a') > -1 // 通过lastInd ...
- XLSReadWriteII5使用参考
varxls: TXLSReadWriteII5 xls.Filename 文件名xls.Read 开始读取xls.Count sheet总数xls.Sheets[i].Name sheet名xls. ...
- 【jdbc访问数据库获取执行sql转换json】
Talk is cheap.Show me your code. import java.sql.*; import java.util.HashMap; import java.util.Map; ...
- MATLAB矩阵运算
1. 矩阵的加减乘除和(共轭)转置 (1) 矩阵的加法和减法 如果矩阵A和B有相同的维度(行数和列数都相等),则可以定义它们的和A+B以及它们的差A-B,得到一个与A和B同维度的矩阵C,其中Cij=A ...
- 将pucharm与anaconda配合使用
一个用来更新各种包,另一个负责美美的打代码,把pycharm, setting project interpreter,选中anaconda中的python.exe.搞定.anaconda prom ...
- Mac对gdb签名
codesign -f -s gdb-cert $(which gdb) gdb_cert为自己创建的证书名 添加证书信任 activity-monitor双击taskgated 关闭 gdb成功运行
- android模拟器访问PC本地接口
一般来讲PC本地接口是localhost:8080 而在安卓模拟器上用的话,他会映射模拟器本身的,也就是说,可以把模拟器也当成一个PC端来看待,这样会好理解点吧 而在模拟器上想要访问PC本地的loca ...
- 使用datagrid时json的格式
EasyUI的DataGrid要求返回的JSON数据集是这样的形式: {"total":总记录数量,"rows":[数据记录数组]}. 例如: {"t ...
- 判断是否引入jQuery,没有则引入
<script type="text/javascript"> window.jQuery || document .write("<script sr ...
- FB面经 Prepare: LCA of Deepest Nodes in Binary Tree
给一个 二叉树 , 求最深节点的最小公共父节点 . retrun . 先用 recursive , 很快写出来了, 要求用 iterative . 时间不够了... Recursion: 返回的时候返 ...