asp.net – 向GridView添加默认排序箭头
发布时间:2020-12-16 03:34:17 所属栏目:asp.Net 来源:网络整理
导读:我是 Asp.net的新手,我目前正在使用GridViews.我浏览了这个网站,其他人已经看到了如何向列标题添加排序箭头的提示. 到目前为止我已经这样做了: 设置这些GridView属性: SortedAscendingHeaderStyle-CssClass="sortasc"SortedDescendingHeaderStyle-CssClass
我是
Asp.net的新手,我目前正在使用GridViews.我浏览了这个网站,其他人已经看到了如何向列标题添加排序箭头的提示.
到目前为止我已经这样做了: 设置这些GridView属性: SortedAscendingHeaderStyle-CssClass="sortasc" SortedDescendingHeaderStyle-CssClass="sortdesc" 我的CSS有这个: th.sortasc a { display:block; padding:0 4px 0 15px; background:url("images/icons/ascArrow.png") no-repeat; } th.sortdesc a { display:block; padding:0 4px 0 15px; background:url("images/icons/descArrow.png") no-repeat; } 这非常适合在用户单击标题并对列进行排序后显示图像. 我现在遇到的问题是,我希望列默认显示图像,以便用户可以知道他们可以点击它们进行排序.有没有办法实现这个目标? 解决方法
您可以在RowCreated事件中显示用于排序gridview列行为的箭头,我通常这样做
protected void GridView1_RowCreated(object sender,GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.Header) { foreach (TableCell tc in e.Row.Cells) { if (tc.HasControls()) { // search for the header link LinkButton lnk = (LinkButton)tc.Controls[0]; if (lnk != null && GridView1.SortExpression == lnk.CommandArgument) { // inizialize a new image System.Web.UI.WebControls.Image img = new System.Web.UI.WebControls.Image(); // setting the dynamically URL of the image img.ImageUrl = "~/img/ico_" + (GridView1.SortDirection == SortDirection.Ascending ? "asc" : "desc") + ".gif"; // adding a space and the image to the header link tc.Controls.Add(new LiteralControl(" ")); tc.Controls.Add(img); } } } } } 它还会在列的升序和降序排序中切换图像 代码实际上做的是它 AnswerSource (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc – asp.net mvc 4 – 好的是每个线程共享DbCon
- asp.net-mvc – 错误2002:MetadataWorkspace中不存在指定为
- 处理asp.net core EF model 中有自增列的问题
- iis-7.5 – .NET MVC 3动作是否应该触发w3wp.exe以生成进程
- 如何在ASP.NET中的主题之间共享.skin主题文件?
- asp.net – 在.net中输入密钥和多个提交按钮
- asp.net-mvc – 在ASP.NET核心中创建单元测试
- asp.net-mvc-4 – 发布后保留表单值(不是模型的一部分)
- asp.net-mvc – 使用Repository/Service Pattern和MVC时缓存
- asp.net-mvc-4 – MVC 4 Razor如果拆分div标签
推荐文章
站长推荐
- asp.net – 使用jQuery调用MVC中的action方法,参
- asp.net-identity-2 – GenerateEmailConfirmati
- asp.net – Page.IsValid如何工作?
- 无法获得突出显示的asp.net开始页面jquery |回发
- asp.net-mvc – 如何使用asp.net mvc EditorTemp
- asp.net-mvc – 为什么我不能在ASP.NET视图中设置
- asp.net-mvc – 为什么Razor会添加另一个值属性以
- asp.net-mvc – HTML.Hidden For value set
- asp.net – 对象“aspnet_CheckSchemaVersion”,
- Asp.Net Core 进阶(一) —— 读取appsettings.
热点阅读