Blog b = new Blog("marcos blog"); RSS 2.0
# Thursday, September 27, 2007

Setzt man das SharePoint GridView (Microsoft.SharePoint.WebControls.SPGridView) in eigenen Seiten ein, und benutzt man für die Datenquelle die DataSource Eigenschaft

spGridView.DataSource = dataView;

dann zeigt das GridView beim sortieren keine Pfeile neben der sortierten Spalte an.

Dank Reflector stellt man fest, dass das SPGridView leider die Spalten Sortierung nur anzeigt wenn man als Datenquelle "DataSourceID" verwendet... Warum? Ich sehe da keinen Grund. Deshalb hier in etwa die Implementierung wie es das SPGridView auch intern macht:

      public static void SetGridViewSortArrow(SPGridView spGridView, string sortExpression, SortDirection sortDirection)
      {
         // Show arrow on sorted column
         for (int colIndex = 0; colIndex < spGridView.Columns.Count; colIndex++)
         {
            DataControlField field = spGridView.Columns[colIndex];
            if (((field == null) || string.IsNullOrEmpty(field.SortExpression)) 
|| (field.SortExpression.ToLower(CultureInfo.CurrentCulture) != sortExpression.ToLower(CultureInfo.CurrentCulture))) continue; DataControlFieldHeaderCell cell2 = (DataControlFieldHeaderCell)spGridView.HeaderRow.Cells[colIndex]; Image image = new Image(); if (sortDirection == SortDirection.Ascending) image.ImageUrl = "/_layouts/images/sortup.gif"; else image.ImageUrl = "/_layouts/images/sortdown.gif"; image.Style[System.Web.UI.HtmlTextWriterStyle.MarginLeft] = "2px"; cell2.Controls.Add(image); break; } }

Aufgerufen wird das ganze dann im gridView_Sorting Event nach dem sortieren und vor allem nach dem

spGridView.DataBind();
Thursday, September 27, 2007 1:25:29 PM (W. Europe Standard Time, UTC+01:00)  #    Comments [1]
.NET | ASP.NET 2.0 | C# Code | Microsoft | SharePoint
Thursday, August 21, 2008 1:46:52 PM (W. Europe Standard Time, UTC+01:00)
Ein ähnliches Problem gibt es beim Filter-Icon. Auch dieses wird nicht vom SPGridView nicht selbstständig dargestellt. Angeregt durch Deinen Artikel habe ich mich mal hingesetzt und ein eignes Beispiel für eine SPGridView-Implementierung inkl. Sortierung, Paginierung und Filterung.

Gruß,
Oliver

http://www.sharepointblogs.com/wirkus/archive/2008/08/21/how-to-professionelle-datenanzeige-mit-dem-control-spgridview.aspx
OpenID
Please login with either your OpenID above, or your details below.
Name
E-mail
(will show your gravatar icon)
Home page

Comment (Some html is allowed: a@href@title, b, strike, strong) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.  

Enter the code shown (prevents robots):

Live Comment Preview
Statistics
Total Posts: 192
This Year: 4
This Month: 1
This Week: 0
Comments: 291


Sign In
All Content © 2010, Marco Wiedemeyer
DasBlog theme 'Business' created by Christoph De Baene (delarou)