Share via


SPView.GroupByHeader Property

Gets or sets the definition of the Group By header used in the view.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

Syntax

Public Property GroupByHeader As String
    Get
    Set

Dim instance As SPView
Dim value As String

value = instance.GroupByHeader

instance.GroupByHeader = value
public string GroupByHeader { get; set; }

Property Value

Type: System.String
A Collaborative Application Markup Language (CAML) string that contains the header definition.

Remarks

If you set values through the GroupByHeader property, you must use the Update method for changes to take effect in the database.

Examples

The following code example uses the GroupByHeader property to customize the font size, font color, and background color of the Group By header area in a view within a specified site of the current site collection.

Dim siteColl As SPSite = SPControl.GetContextSite(Context)
Dim site As SPWeb = siteColl.AllWebs("Site_Name")
Dim list As SPList = site.Lists("List_Name")
Dim view As SPView = list.Views("View_Name")

view.GroupByHeader = "<HTML><![CDATA[<TBODY id='titl]]></HTML>" _
    & "<GetVar Name='GroupByLevelString' />" _
    & "<HTML><![CDATA['><TR STYLE='font-size:14pt;color:red']]></HTML>" 
        _
    & "<Switch><Expr><GetVar Name='GroupByIndent' /></Expr>
        <Case Value='0'>" _
    & "<HTML><![CDATA[ class='ms-gb' ]]></HTML></Case><Default>" _
    & "<HTML><![CDATA[ class='ms-gb2' ]]></HTML></Default></Switch>" _
    & "<HTML><![CDATA[><TD colspan='100' nowrap BGCOLOR='white'>" _
    & "<img src='/_layouts/images/blank.gif' alt='' height=1 width=]]>" 
        _
    & "</HTML><GetVar Name='GroupByIndent' />" _
    & "<HTML><![CDATA[><a href='javascript:' 
        onclick='javascript:ExpCollGroup(']]></HTML>" _
    & "<GetVar Name='GroupByLevelString' />
        <HTML><![CDATA[','img_]]></HTML>" _
    & "<GetVar Name='GroupByLevelString' />
        <HTML><![CDATA[');return false;'><img id='img_]]></HTML>" _
    & "<GetVar Name='GroupByLevelString' />
        <HTML><![CDATA[' src='/_layouts/images/minus.gif' 
        alt=']]></HTML>" _
    & "<HTML>Expand/Collapse</HTML>
        <HTML><![CDATA[' border='0'></a>&amp;nbsp;]]></HTML>" _
    & "<GetVar Name='GroupByField' HTMLEncode='TRUE' />
        <HTML><![CDATA[ :&amp;nbsp;]]></HTML>" _
    & "<GetVar Name='GroupByValue' />
        <HTML><![CDATA[</TD></TR></TBODY>]]></HTML>" _
    & "<HTML><![CDATA[<TBODY id='tbod]]></HTML>
        <GetVar Name='GroupByLevelString' HTMLEncode='TRUE' />" _
    & "<HTML><![CDATA[_'>]]></HTML><SetVar Name='EvenRow' 
        Scope='Request' Value='0' />" _
    & "<SetVar Name='OnlyOneItem' Scope='Request' Value='1' />"

view.Update() 
SPSite oSiteCollection = SPContext.Current.Site;
using(SPWeb oWebsite = oSiteCollection.AllWebs["Website_Name"])
{
   SPList oList = oWebsite.Lists["List_Name"];
   SPView oView = oList.Views["View_Name"];

    oView.GroupByHeader = 
   "<HTML><![CDATA[<TBODY id=\"titl]]></HTML>" +
   "<GetVar Name=\"GroupByLevelString\" />" + 
   "<HTML><![CDATA[\"><TR STYLE=\"font-size:14pt;color:red\"]]></HTML>" 
      +
   "<Switch><Expr><GetVar Name=\"GroupByIndent\" /></Expr>
      <Case Value=\"0\">" +
   "<HTML><![CDATA[ class=\"ms-gb\" ]]></HTML></Case><Default>" + 
   "<HTML><![CDATA[ class=\"ms-gb2\" ]]></HTML></Default></Switch>" + 
   "<HTML><![CDATA[><TD colspan=\"100\" nowrap BGCOLOR=\"white\">" + 
   "<img src=\"/_layouts/images/blank.gif\" alt=\"\" height=1 
      width=]]>" + 
   "</HTML><GetVar Name=\"GroupByIndent\" />" +
   "<HTML><![CDATA[><a href=\"javascript:\" 
      onclick=\"javascript:ExpCollGroup(']]></HTML>" + 
   "<GetVar Name=\"GroupByLevelString\" />
      <HTML><![CDATA[','img_]]></HTML>" +
   "<GetVar Name=\"GroupByLevelString\" />
      <HTML><![CDATA[');return false;\"><img id=\"img_]]></HTML>" + 
   "<GetVar Name=\"GroupByLevelString\" />
      <HTML><![CDATA[\" src=\"/_layouts/images/minus.gif\" 
      alt=\"]]></HTML>" +
   "<HTML>Expand/Collapse</HTML>
      <HTML><![CDATA[\" border=\"0\"></a>&nbsp;]]></HTML>" + 
   "<GetVar Name=\"GroupByField\" HTMLEncode=\"TRUE\" />
      <HTML><![CDATA[ :&nbsp;]]></HTML>" + 
   "<GetVar Name=\"GroupByValue\" />
      <HTML><![CDATA[</TD></TR></TBODY>]]></HTML>" + 
   "<HTML><![CDATA[<TBODY id=\"tbod]]></HTML>
      <GetVar Name=\"GroupByLevelString\" HTMLEncode=\"TRUE\" />" + 
   "<HTML><![CDATA[_\">]]></HTML><SetVar Name=\"EvenRow\" 
      Scope=\"Request\" Value=\"0\" />" + 
   "<SetVar Name=\"OnlyOneItem\" Scope=\"Request\" Value=\"1\" />";
    oView.Update();
}

Note

Certain objects implement the IDisposable interface, and you must avoid retaining these objects in memory after they are no longer needed. For information about good coding practices, see Best Practices: Using Disposable Windows SharePoint Services Objects.

See Also

Reference

SPView Class

SPView Members

Microsoft.SharePoint Namespace