When dealing with ObjectDataSource or EntityDataSource, how do you add a sorting image to the GridView Header?

asp.net c# entity-framework gridview objectdatasource

Question

I want to know how can we use sorting image inside GridView header while we use ObjectDataSource or Entity Framework. Because that has direct calling feature and also having sorting expression.

So, how can i use GridView.RowCreated event and get the sort expression to bind the sorting image?

1
1
7/15/2011 10:24:13 AM

Accepted Answer

That was for older ASP.NET 2.0 days. ASP.NET 4.0 allows us to specify it as a asp:GridView property

MSDN Links

  1. SortedAscendingHeaderStyle
  2. SortedDescendingHeaderStyle

GridView Markup

<SortedAscendingHeaderStyle CssClass="sortasc" />
<SortedDescendingHeaderStyle CssClass="sortdesc" />

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; }

Please note that the asp:GridView has been assigned CssClass="datatable".

You might also want to check out SortedAscendingCellStyle and SortedDescendingCellStyle

For old fashioned way, try this. http://mattberseth.com/blog/2007/10/a_yui_datatable_styled_gridvie.html

5
7/16/2011 1:42:14 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow