Sunday, January 10, 2016

XSLT style for - First Row xslt using choose

  <xsl:for-each select="$Rows">
    <xsl:variable name="thisNode" select="."/>
    <xsl:variable name="ID" select="$thisNode/@ID"/>
    <xsl:variable name="Title" select="$thisNode/@Title"/>
    <xsl:variable name="Logo" select="$thisNode/@Logo"/>   
      <xsl:choose>
        <xsl:when test="position() = 1">
         <div class="first">
             <a href="#" onclick="openWindow();" ><img src="{$Logo}" alt="{$Title}" /></a>
         </div>   
        </xsl:when>
          <xsl:otherwise>
             <div class="others">
                <a href="#" onclick="openWindow();" ><img src="{$Logo}" alt="{$Title}" /></a>
              </div>       
          </xsl:otherwise>
      </xsl:choose>       
   </xsl:for-each>

Sunday, January 3, 2016

Adding Rating Control on SharePoint List Item Forms in SharePoint 2013

First of all, you need to enable the Ratings on the list from list settings page where you would like to include the ratings. You will be able to see Ratings column in the list views.

 I googled and read many blogs but most of them mentioned updating/creating a layout page. Now what I wanted to have is the rating column being available on the display item form of the list for a particular list item.

So to be precise, we need to:
  • Create a Visual/Custom web part
  • Add Reference to Microsoft.SharePoint.Portal
  • Register the SharePoint Portal Control
    <%@ Register Tagprefix="SharePointPortalControls" Namespace="Microsoft.SharePoint.Portal.WebControls" Assembly="Microsoft.SharePoint.Portal, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
  •  Add the following Code in the .ascx:
      <asp:Panel ID="panelRating" runat="server">
        </asp:Panel>
  • On Page Load:

    HttpContext context = HttpContext.Current;
                SPList currentList = SPContext.Current.List;
                SPListItem currentItem = SPContext.Current.ListItem;
                AverageRatingFieldControl ratingCntrl = new AverageRatingFieldControl();
                ratingCntrl.ID = "RatingCntrl";
                ratingCntrl.ListId = currentList.ID;
                ratingCntrl.ControlMode = SPControlMode.Edit;
                ratingCntrl.FieldName = "AverageRating";
                ratingCntrl.ItemContext = SPContext.GetContext(context, currentItem.ID, currentList.ID, SPContext.Current.Web);
                panelRating.Controls.Add(ratingCntrl);
 This will get the rating of the current item and can be updated by the user and can be used on display/edit forms of the List.


 

References: