如何在使用ObjectDataSource或EntityDataSource时将排序图像添加到GridView标头

shr*_*rum 1 c# asp.net gridview entity-framework objectdatasource

我想知道GridView在使用ObjectDataSource或实体框架时我们如何在头部内使用排序图像.因为它具有直接调用功能并且还具有排序表达式.

那么,我如何使用GridView.RowCreated事件并获取排序表达式来绑定排序图像?

nav*_*een 5

这是旧的ASP.NET 2.0天.ASP.NET 4.0允许我们将其指定为asp:GridView属性

MSDN链接

  1. SortedAscendingHeaderStyle
  2. SortedDescendingHeaderStyle

GridView标记

<SortedAscendingHeaderStyle CssClass="sortasc" />
<SortedDescendingHeaderStyle CssClass="sortdesc" />
Run Code Online (Sandbox Code Playgroud)

CSS

.datatable th
{
    font-size:12px;
    font-weight:bold;
    letter-spacing:0px;
    text-align:left;
    padding:2px 4px;
    color:#333333;
    border-bottom:solid 2px #bbd9ee;
}
.datatable th a
{ 
    text-decoration:underline;
    padding-right:18px; 
    color:#000;
}
.datatable th.sortasc a { background:url(../Images/asc.gif) right center no-repeat; }
.datatable th.sortdesc a { background:url(../Images/desc.gif) right center no-repeat; }
Run Code Online (Sandbox Code Playgroud)

请注意,asp:GridView已分配CssClass="datatable".

您可能还想查看SortedAscendingCellStyleSortedDescendingCellStyle

对于老式的方式,试试这个.http://mattberseth.com/blog/2007/10/a_yui_datatable_styled_gridvie.html