Showing posts with label SharePoint. Show all posts
Showing posts with label SharePoint. Show all posts

Monday, August 29, 2016

LoginView Control in SharePoint Web Part

When developing on a SharePoint site, if you have the need to show your logged in users content that you don't necessarily want to show your anonymous users, the LoginView control is for you.

Keeping it simple, we pass a string to the LoggedInTemplate class constructor that inherits from the iTemplate interface.

// we'll show the label only when a user is logged in. Intended for employees only.
LoginView lv = new LoginView();
Label usernameLabel = new Label();
usernameLabel.Text = "Hello There";
lv.LoggedInTemplate = new LoginViewTemplate(usernameLabel);
Controls.Add(lv);

// Logged in user and anonymous templates inherited from iTemplate interface.
    class LoginViewTemplate : ITemplate
    {
        private Label _label;
        public LoginViewTemplate(Label label)
        {
            _label = label;
        }
        public void InstantiateIn(Control container)
        {
            container.Controls.Add(_label);
        }
    }

// not used in this example
    class AnonymousTemplate : ITemplate
    {
        private Label _label;
        public AnonymousTemplate(Label label)
        {
            _label = label;
        }
        public void InstantiateIn(Control container)
        {
            container.Controls.Add(_label);
        }
    }

For further filtering out your logged in users to see specific content, use RoleGroups instead.

Thursday, September 11, 2014

Using PowerShell to find the GUID of an SPField instance

In SharePoint, I occasionally need to find the GUID of a field in a custom list. The following PowerShell will spit out the field's GUID:


$web=get-spweb https://mysite.com/mysite/
$list=$web.lists["My List Display Name"]
$list.fields["MyFieldName"].id

Wednesday, August 27, 2014

Looking for at least one checked checkbox in Multiple-Selection List Box groups using X-Path in InfoPath


In a scenario involving multiple groups of Multiple-Selection List Boxes where I needed to check and see if at least one checkbox was checked in an InfoPath form, I used a Calculated Field to display a message if no checkboxes were checked. Checking for at least one box checked can be accomplished by using the following X-Path expression:

substring("Text to show if no checkboxes selected", 1, (not(boolean(xdMath:Eval(dfs:dataFields/my:SharePointListItem_RW/my:ListBox1/Value[. != ""], "."))) and
not(boolean(xdMath:Eval(dfs:dataFields/my:SharePointListItem_RW/my:ListBox2/Value[. != ""], "."))) and
not(boolean(xdMath:Eval(dfs:dataFields/my:SharePointListItem_RW/my:ListBox3/Value[. != ""], ".")))) *
string-length("Text to show if no checkboxes selected"))

The condition evaluates to True (1) if no boxes are checked, False (0) if any box is checked. These 1 or 0 values are multiplied by the length of the text and serve as the third parameter in the substring function, determining the length of the substring.

Thursday, February 20, 2014

Updating SharePoint Ribbon Styles and Markup Styles

The SharePoint 2010 Ribbon contains default styles and elements in their Styles and Markup Styles sections. Using CSS, you can add styles or elements as well as hide OOTB styles and elements.

To create new items, use the ms-rteElement or ms-rteStyle prefixes in your CSS file.

H2.ms-rteElement-H2Custom
{
     -ms-name:Title;
     color:#008C99;
     background-color:transparent;
 }

.ms-rteStyle-Normal
{
      -ms-name:"Normal";
      font-size:10pt;
      font-weight:normal;
      background-color:transparent;
}

To remove the Styles button entirely:

#Ribbon\.EditingTools\.CPEditTab\.Styles
{
      display:none;
}

To remove a single element from the Markup Styles list (Change the ElementWithStyle index number to hide the element based on its order in the list.):

li.ms-cui-menusection-items a#ElementWithStyle0-Menu
{
      display:none;
}
li.ms-cui-menusection-items a#ElementWithStyle1-Menu
{
      display:none;
}

Thursday, October 24, 2013

SharePoint Custom List web part template

A recent project involved adding the same navigation links to a couple of SharePoint blog sites. The navigation links must appear on the default.aspx, categories.aspx and post.aspx pages. Using a custom list in the parent site, we created a web part using SP Designer. Now, if we need another navigation web part for another set of blogs, we can simply export the web part and make the necessary changes. Below is the content of web part. Included is the xml definition of the view as well as the xsl to create the links.

<?xml version="1.0" encoding="utf-8" ?>
<webParts>
 <webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
  <metaData>
   <type name="Microsoft.SharePoint.WebPartPages.XsltListViewWebPart, Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
   <importErrorMessage>Cannot import this Web Part.</importErrorMessage>
  </metaData>
  <data>
   <properties>
    <property name="InitialAsyncDataFetch" type="bool">False</property>
    <property name="ChromeType" type="chrometype">None</property>
    <property name="Title" type="string" />
    <property name="Height" type="string" />
    <property name="CacheXslStorage" type="bool">True</property>
    <property name="XslLink" type="string" null="true" />
    <property name="AllowZoneChange" type="bool">True</property>
    <property name="AllowEdit" type="bool">True</property>
    <property name="XmlDefinitionLink" type="string" />
    <property name="DataFields" type="string" />
    <property name="Hidden" type="bool">False</property>
    <property name="ListName" type="string">{37683D39-B11D-4E11-8B1C-8C5421EDB458}</property>
    <property name="NoDefaultStyle" type="string">TRUE</property>
    <property name="ListDisplayName" type="string" null="true" />
    <property name="AutoRefresh" type="bool">False</property>
    <property name="ViewFlag" type="string">8388621</property>
    <property name="AutoRefreshInterval" type="int">60</property>
    <property name="AllowConnect" type="bool">True</property>
    <property name="Description" type="string" />
    <property name="AllowClose" type="bool">True</property>
    <property name="ShowWithSampleData" type="bool">False</property>
    <property name="ParameterBindings" type="string"></property>
     <property name="EnableOriginalValue" type="bool">False</property>
    <property name="CacheXslTimeOut" type="int">86400</property>
    <property name="WebId" type="System.Guid, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">ef069fb2-2b0b-4c00-ad1f-231d5485f963</property>
    <property name="ListUrl" type="string" null="true" />
    <property name="DataSourceID" type="string" />
    <property name="FireInitialRow" type="bool">True</property>
    <property name="ManualRefresh" type="bool">False</property>
    <property name="ViewFlags" type="Microsoft.SharePoint.SPViewFlags, Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c">Html, TabularView, Hidden, Mobile</property>
    <property name="ChromeState" type="chromestate">Normal</property>
    <property name="AllowHide" type="bool">True</property>
    <property name="PageSize" type="int">-1</property>
    <property name="SampleData" type="string" null="true" />
    <property name="BaseXsltHashKey" type="string">/_layouts/xsl/vwstyles.xsl;#12/13/2011 02:25:36;#0;#/_layouts/xsl/fldtypes.xsl;#03/26/2010 21:24:40;#0;#/_layouts/xsl/fldtypes_Ratings.xsl;#03/14/2012 11:19:12;#0;#/_layouts/xsl/fldtypes_docicon.xsl;#09/07/2011 11:41:41;#0;# 1 100  14.0.6120.5000</property>
    <property name="AsyncRefresh" type="bool">False</property>
    <property name="HelpMode" type="helpmode">Modeless</property>
    <property name="ListId" type="System.Guid, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">37683d39-b11d-4e11-8b1c-8c5421edb458</property>
    <property name="DataSourceMode" type="Microsoft.SharePoint.WebControls.SPDataSourceMode, Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c">List</property>
    <property name="AllowMinimize" type="bool">True</property>
    <property name="TitleUrl" type="string">/XXXXX/XXX/Lists/Navigation</property>
    <property name="CatalogIconImageUrl" type="string" />
    <property name="DataSourcesString" type="string" />
    <property name="PageType" type="Microsoft.SharePoint.PAGETYPE, Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c">PAGE_NORMALVIEW</property>
    <property name="DisplayName" type="string">All Items</property>
    <property name="UseSQLDataSourcePaging" type="bool">True</property>
    <property name="Width" type="string" />
    <property name="ExportMode" type="exportmode">All</property>
    <property name="Direction" type="direction">NotSet</property>
    <property name="ViewContentTypeId" type="string">0x</property>
    <property name="HelpUrl" type="string" />
    <property name="XmlDefinition" type="string">
    &lt;View Name="{E9A835C7-4605-41BD-AA5E-50D9799DE2C9}" MobileView="TRUE" Type="HTML" Hidden="TRUE" DisplayName="All Items" Url="/academic-affairs/AFA/SitePages/Untitled_12.aspx" Level="1" BaseViewID="1" ContentTypeID="0x" ImageUrl="/_layouts/images/generic.png"&gt;
     &lt;Query/&gt;
     &lt;ViewFields&gt;
      &lt;FieldRef Name="LinkTitle"/&gt;
      &lt;FieldRef Name="URL"/&gt;
      &lt;FieldRef Name="Title" Explicit="TRUE"/&gt;
     &lt;/ViewFields&gt;
     &lt;/View&gt;
    </property>   
     <property name="Xsl" type="string">
    &lt;xsl:stylesheet xmlns:x="http://www.w3.org/2001/XMLSchema" xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" version="1.0" exclude-result-prefixes="xsl msxsl ddwrt" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:SharePoint="Microsoft.SharePoint.WebControls" xmlns:ddwrt2="urn:frontpage:internal" xmlns:o="urn:schemas-microsoft-com:office:office" ddwrt:ghost="show_all"&gt;
    &lt;xsl:template match="dsQueryResponse" xmlns:x="http://www.w3.org/2001/XMLSchema" xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:SharePoint="Microsoft.SharePoint.WebControls" xmlns:o="urn:schemas-microsoft-com:office:office" ddwrt:ghost="" xmlns:ddwrt2="urn:frontpage:internal" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime"&gt;       
     &lt;div class="AFANavigation"&gt;&lt;xsl:apply-templates select="/dsQueryResponse/Rows/Row"/&gt;&lt;/div&gt;
    &lt;/xsl:template&gt;
       &lt;xsl:template match="Row"&gt;
      &lt;xsl:choose&gt;
       &lt;xsl:when test="substring(@URL,2,3) = 'a h'"&gt;
        &lt;xsl:variable name="link" select="substring-after(substring-before(@URL,'&amp;lt;/a&amp;gt;'),'&amp;gt;')"/&gt;
        &lt;div&gt;&lt;a href="{$link}"&gt;&lt;xsl:value-of select="@Title"/&gt;&lt;/a&gt;&lt;/div&gt;
       &lt;/xsl:when&gt;
      &lt;xsl:otherwise&gt;
       &lt;div&gt;&lt;a href="{@URL}"&gt;&lt;xsl:value-of select="@Title"/&gt;&lt;/a&gt;&lt;/div&gt;
      &lt;/xsl:otherwise&gt;
     &lt;/xsl:choose&gt;
        &lt;/xsl:template&gt;
    &lt;/xsl:stylesheet&gt;
    </property>

    <property name="Default" type="string">FALSE</property>
    <property name="TitleIconImageUrl" type="string" />
    <property name="MissingAssembly" type="string">Cannot import this Web Part.</property>
    <property name="SelectParameters" type="string" />
   </properties>
  </data>
 </webPart>
</webParts>

Friday, September 20, 2013

Using the following-sibling to compare node-sets in a SharePoint list


In a table I need to display items from a SharePoint custom list grouped by a column. For styling purposes, I need to identify the last row of each grouping. Using the following-sibling axis, I can look ahead to see if the group value will change. If so, I apply a class to the current table row.

<xsl:template match='Row'>
<tr>
<xsl:if test="@Group != following-sibling::Row[1]/@Group or position() = last()">
     <xsl:attribute name="class">lastItem</xsl:attribute>
 </xsl:if>
....
</tr>
...
</xsl:template>

In my stylesheet, I can then apply rules to the lastItem class:

table  tr { border-bottom: 2px #707070 dotted; }
table tr.lastItem { border-bottom: none; }

Tuesday, July 2, 2013

Including a link to a javascript file in XSLT

In SharePoint 2010, I was updating a custom version of the ContentQueryMain.xsl file, needing to include javascript for the page. When I added the following code, the layout of the page changed, the ribbon stopped responding and the page would not respond when in edit mode.

<script type="text/javascript" src="/Script%20Files/myjavascript.js"></script> 

Turns out, the XSLT processor didn't care for the empty script tag. Adding the space entity &#160; fixed the problem.

<script type="text/javascript" src="/Script%20Files/myjavascript.js">&#160;</script>

 

Thursday, April 4, 2013

Using Request.QueryString in Page_Load in SharePoint page layout


Below is an example of using the Request.QueryString collection in the Page_Load method in a SharePoint page layout. In this case we're looking for the variable named 'tab' and checking for various conditions.


try
{
  int index = System.Convert.ToInt32(Request.QueryString["tab"]);
  if (index > 1 && index < 5)
  {
    if (RadTabStrip1.Tabs[index-1].Visible)
    {
       RadTabStrip1.Tabs[index-1].Selected = true;
       RadMultiPage1.PageViews[index-1].Selected = true;
    }
  }
}
catch (Exception ex)
{
  //    Response.Write(ex.Message);
}

Thursday, March 28, 2013

Using word-wrap for an AspMenu SharePoint web control with long menu items

I have an AspMenu SharePoint web control with long menu items that do not respect the width of the table cell that I've set even though I have the property 'ItemWrap' set to 'True'. The biggest culprit is users wanting to use a series of  underscores to separate one group od links from another. To keep an extra long series of underscores from pushing the table cell wider, I'm using the stylesheet rule 'word-wrap' as shown below.

The ASPMenu control creates this hierarchy of tables. 

div#s4-leftpanel table tr td table
{
       table-layout:fixed;
}
div#s4-leftpanel table tr td table tr td
{
       word-wrap:break-word;
}

Monday, March 11, 2013

Hiding SharePoint list columns from NewForm.aspx using JavaScript

There are times I create a column in a SharePoint custom list and I don't want anyone with Contribute rights to alter the default value. In the NewForm.aspx and EditForm.aspx pages I add the following script to a CEWP on the page.

<script type="text/javascript">
  function HideField(title){
   var header_h3 = document.getElementsByTagName("h3");
   for (var i = 0; i < header_h3.length; i++)
   {
       var el = header_h3[i];
       var foundField;
       if (el.className=="ms-standardheader")
       {
           for (var j=0; j<el.childNodes.length; j++)
           {
              if (el.childNodes[j].innerHTML == title || el.childNodes[j].nodeValue == title)
             {
                 var elRow = el.parentNode.parentNode;
                 elRow.style.display = "none"; //and hide the row
                 foundField = true;
                 break;
         }
      }       
    }
     if (foundField)
  break;
 }
}
HideField("Workspace");
HideField("Remote Item ID");
</script>

Thursday, February 21, 2013

Content Query Web Part using Custom ItemStyle.xsl


To set an existing Content Query Web part to use a custom ItemStyle.xsl file for custom styling list entries, we need to update the following property in the Content Query Web Part.webpart file after exporting to the Desktop.
<property name="ItemXslLink" type="string">/Style Library/XSL Style Sheets/ItemStyleCustom.xsl</property>
After uploading back to the page, the web part now allows you to choose custom item templates in the ItemStyleCustom.xsl file you've created.

Friday, February 15, 2013

SPDataSource and the CrossList DataSourceMode


I was recently searching for how to construct an SPDataSource using a Crosslist or Union of two or more SharePoint lists. Not finding the answer in one place, I was able to piece together the answer. Because we're doing a union of lists, the column names and type in each list must match.


<SharePointWebControls:SPDataSource
runat="server"
ID="spDataSource1"
DataSourceMode="CrossList"
SelectCommand="<Webs Scope='SiteCollection'></Webs>
  <Lists>
    <List ID='XXXXXXXX-XXXX-4499-91F3-359A463EB89F'></List>
    <List ID='XXXXXXXX-XXXX-4EBE-9801-8751A076F069'></List>
  </Lists>
  <View>
    <ViewFields><FieldRef Name='Title' /><FieldRef Name='EventDate' /><FieldRef Name='EndDate' /></ViewFields>
    <Query>
      <Where><Geq><FieldRef Name='EndDate'/><Value  Type='DateTime'><Today/></Value></Geq>
      </Where>
      <OrderBy><FieldRef Name='EventDate' Ascending='True'/></OrderBy>
    </Query>
    <RowLimit>5</RowLimit>
  </View>"

</SharePointWebControls:SPDataSource>

Friday, December 7, 2012

Getting List Items from a SharePoint List using SOAP

Use the steps below to get list items from a SharePoint list using SOAP.

First construct your xml SOAP message:


StringBuilder sbEnvelope = new StringBuilder();
sbEnvelope.Append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
sbEnvelope.Append("<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">");

sbEnvelope.Append("<soap:Body><GetListItems xmlns=\"http://schemas.microsoft.com/sharepoint/soap/\">
<listName>" + listname + "</listName><viewName>" + viewName + "</viewName>" +
 "<query></query><viewFields><ViewFields><FieldRef Name='Column1' /><FieldRef Name='Column2' /><FieldRef Name='Column3' /></ViewFields></viewFields></GetListItems></soap:Body></soap:Envelope>");

Next, construct your HttpWebRequest, get your response and place it in an XmlDocument for parsing.


HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://<site>/_vti_bin/lists.asmx");
req.Method = "POST";
req.ContentType = "text/xml; charset=\"utf-8\"";
req.Accept = "text/xml";
req.Headers.Add("SOAPAction", "http://schemas.microsoft.com/sharepoint/soap/GetListItems");
req.UseDefaultCredentials = true;

using (Stream stream = req.GetRequestStream()) 
{
      using (StreamWriter writer1 = new StreamWriter(stream)) 
     {
            writer1.Write(sbEnvelope.ToString());
      }
}

WebResponse response = req.GetResponse();
Stream responseStream = response.GetResponseStream();

XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load(responseStream);

Finally, create your namespaces and parse the xml.


XmlNamespaceManager manager = new XmlNamespaceManager(xmlDocument.NameTable);
manager.AddNamespace("sp", "http://schemas.microsoft.com/sharepoint/soap/");
manager.AddNamespace("rs", "urn:schemas-microsoft-com:rowset");
manager.AddNamespace("z", "#RowsetSchema");
manager.AddNamespace("y", "http://schemas.microsoft.com/sharepoint/soap/ois");
manager.AddNamespace("w", "http://schemas.microsoft.com/WebPart/v2");
manager.AddNamespace("d", "http://schemas.microsoft.com/sharepoint/soap/directory");

XmlNodeList NodeList = xmlDocument.SelectNodes("//sp:listitems/rs:data", manager);

String t = "";
foreach (XmlNode ListItem in NodeList)
{
     foreach (XmlNode node in ListItem.ChildNodes)
    {
         t = node.Attributes["ows_Title"].Value;
     }
}


Friday, November 16, 2012

XSL for SharePoint List webparts

For out-of-the-box SharePoint List webparts, the 'XSL Link' property allows editors to customize the display of their list data.

Below is an example of an xsl stylesheet for list webparts.

<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:msxsl="urn:schemas-microsoft-com:xslt"
  exclude-result-prefixes="msxsl"
  xmlns:ddwrt2="urn:frontpage:internal">
<xsl:output method="html" indent="yes"/>

<xsl:template match="dsQueryResponse" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime">
  <div class="resourcesList" >
      <xsl:apply-templates select="/dsQueryResponse/Rows/Row"/>
  </div> 
</xsl:template>

<xsl:template match="Row">
    <xsl:if test="position()=1">
    <h2><xsl:value-of select="@Category" disable-output-escaping="yes" /></h2>
    </xsl:if>
    <a href="{substring-before(substring-after(@URL,'&gt;'),'&lt;')}">
     <xsl:value-of select="@Title" disable-output-escaping="yes" />
    </a> <br/>
</xsl:template>

</xsl:stylesheet>

Using XSLT gives a much cleaner and customized look to your list webparts.


Thursday, October 18, 2012

AttachmentField control in SharePoint


The SharePoint AttachmentsField is used to display attachments from an SP list item.

<td align="center" id="att_{@ID}">
<xsl:if test="@Attachments='1'">
<SharePoint:AttachmentsField ID="att{@ID}" ControlMode="Display" ListId="{$ListID}" ItemId="{@ID}" FieldName="Attachments" visible="true" runat="server" />
</xsl:if>
</td>

The HTML that is rendered includes a table with a row for each attachment. The anchor tag look something like:

<a href="/student-affairs/athletics/athletics-w/basketball/Lists/Schedule/Attachments/11/statistics.html">20090312.6.html</a>

Monday, September 24, 2012

Customizing the Summary Links with custom itemStyles.xslt


The Summary Links control (PublishingWebControls:summarylinkfieldcontrol) allows you to specify your own styles using the ItemXslLink property as shown below. 

<PublishingWebControls:summarylinkfieldcontrol ItemXslLink="/Style Library/XSL Style Sheets/InsideHomeItemStyle.xsl" .../>

In SP Designer, you can copy an existing xsl file and rename it, you can then update the file with your own styles and template names.

As a demo of how this works, the following New Home page layout has two Summary Link areas.


The custom itemStyles.xsl file I created has only 2 styles to chose from; insideHome1 & insideHome2. Both styles include a bullet icon in front of the link but insideHome1 colors the link teal, insideHome2 colors the link orange.

If you have a Links Webpart that you've added to a zone in your publishing page, you can export the webpart and modify the webpart file with the following xml:


<property name="HeaderXslLink" type="string">/Style Library/XSL Style Sheets/CustomHeader.xsl</property>
<property name="ItemXslLink" type="string">/Style Library/XSL Style Sheets/CustomItemStyle.xsl</property>

Save, add and upload your webpart. Your new header and styles will now be available.

Wednesday, September 12, 2012

Using the IN Operator in a CAML Query

The In operator is used in an SQL query allows you to specify multiple values in a
WHERE clause. The CAML query language also uses the IN operator, in place of using multiple ORs, to return multiple values of a column.

<In><FieldRef Name='Col1'/>
    <Values>
        <Value Type='Text'>A</Value>
        <Value Type='Text'>B</Value>
        <Value Type='Text'>C</Value>
    </Values>
</In>

Monday, July 30, 2012

Using PowerShell to downgrade a SharePoint v4 site to v3


Use the following powershell commands on a SharePoint front end server to downgrade a v4 site to v3.

$Web=Get-SPWeb http://<site name>/<site>
$Web.UIVersion=3
$Web.UIVersionConfigurationEnabled=$true
$Web.update()

Wednesday, July 18, 2012

Using the Eval method in a SharePoint master or layout page

Examples of using Eval method in SharePoint master or layout page:


In this example "Include Time" is a SP yes/no field where we're checking for a value of "yes":



<%# Eval("Include Time").ToString() == "True" ? " (" + Eval("Start Time","{0:hh:mm tt}") + ")" : "" %>



In this example "Active" is a SP yes/no field where it's casted to a boolean value and then used to control visibility of an asp:Label control:



Visible='<%# bool.Parse(Eval("Active").ToString()) %>'

Another example of setting the Visible property. If the value of Descrition is null, hide the control:

Visible='<%# bool.Parse(Eval("Description") == null ? "False" : "True") %>'

Monday, July 9, 2012

Removing annoying checkboxes in a List web part

When I add a List web part to a page, I'm left with a bunch of annoying check boxes in front of each item, as shown below:










To get rid of these, since they don't really serve any purpose on our public pages, I've added a content editor web part to the page with the following css code. Make sure you add the code using the source editor:

<style type="text/css">
TH.ms-vh-icon {
DISPLAY: none
}
.ms-vb-itmcbx {
DISPLAY: none
}
</style>

I then get a cleaner look to the listing with the check boxes removed from the page.