Tuesday, July 26, 2011

Using the asp:ListView control in SharePoint

Below is example code implementing the asp:ListView control in a SharePoint page. Bound data comes from the SPDataSource control.

The SelectCommand is in the CAML query language which is XML based. The query looks for all Calendar events ending today or later, row limit of 4, sorted by start date. You can also use parameters for a dynamic SelectCommand:

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.webcontrols.spdatasource.selectparameters.aspx

<asp:ListView ID="ListView1" runat="server" DataSourceID="spDataSource1">
<LayoutTemplate>
<div style="background-color: #fffddd; padding: 10px; width: 200px">
<asp:PlaceHolder ID="itemPlaceholder" runat="server"></asp:PlaceHolder>
</div>
</LayoutTemplate>
<ItemTemplate>
<p style="font-size:small;">
<a href="/examples/Lists/Events//DispForm.aspx?ID=<%# Eval("ID") %>" style="color:#787878"><span style='text-decoration:none;<%# Eval("Category").Equals("Holiday") ? "font-weight:bold" : "font-weight:normal" %>'><%# Eval("DisplayDateTime").ToString().Substring(8) %></span><br />
<span style="font-style:italic"><%# Eval("Title") %></span></a></p>
</ItemTemplate>
</asp:ListView>

<SharePointWebControls:SPDataSource runat="server" ID="spDataSource1" DataSourceMode="List" SelectCommand="<Query><Where><Geq><FieldRef Name='EndDate' /><Value Type='DateTime'><Today /></Value></Geq></Where><OrderBy><FieldRef Name='EventDate' Ascending='True' /></OrderBy><RowLimit>4</RowLimit></Query>">
<SelectParameters> <asp:Parameter Name="WebUrl" DefaultValue="/examples/" /> <asp:Parameter Name="ListName" DefaultValue="Events" /> </SelectParameters>
</SharePointWebControls:SPDataSource>

Thursday, July 21, 2011

Creating an SPDataSource .NET control

To use an SP List as a data source for a .NET web control, declare an SPDataSource as shown:

<SharePointWebControls:SPDataSource runat="server" ID="spDataSource1" DataSourceMode="List" SelectCommand="<Query><Where><Eq><FieldRef Name='Section'/><Value Type='Choice'>Get Started</Value></Eq></Where><OrderBy><FieldRef Name='SortOrder' Ascending='True' /></OrderBy></Query>">
<SelectParameters> <asp:Parameter Name="WebUrl" DefaultValue="/student-affairs/enrollment/" /> <asp:Parameter Name="ListName" DefaultValue="Transfer" /> </SelectParameters>
</SharePointWebControls:SPDataSource>


The SelectCommand property allows for filtering and sorting of results.

The ID for this data source will then go inot the DataSourceID field of the web control that uses the SP List, as shown below:

<asp:GridView ID="DataGrid1" runat="server" DataSourceID="spDataSource1">
...
</asp:GridView>

Tuesday, April 26, 2011

Adding a stylesheet to a SharePoint masterpage using the CSSRegistration control

Sharepoint has a .NET control for registering CSS files in a SharePoint masterpage called SharePoint:CSSRegistration. Use the ~Site token to specify the current site. This control goes in the head section of the masterpage.

<SharePoint:CssRegistration name="<% $SPUrl:~Site/CSS/gilariver.css%>" runat="server"/>

New to SharePoint 2010
You can specify the order using the After property. The After property contains the name of the CSS that you want to place the CSS after. The ConditionalExpression parameter will tell the CssLink to render the Conditional-CSS code as well as the CSS link.

Using the RadCaptcha control

RadControls has a RadCaptcha control that can be used in .NET applications or SharePoint web parts. Add the RadCaptcha image handler to the web.config file to use the captcha:

<system.webServer>
...
<handlers>
...
<add name="Telerik.Web.UI.WebResource" path="Telerik.Web.UI.WebResource.axd" verb="*" type="Telerik.Web.UI.WebResource, Telerik.Web.UI, Version=2010.3.1317.35, Culture=neutral, PublicKeyToken=121fae78165ba3d4" />
...
</handlers>
</system.webServer>

Wednesday, April 6, 2011

SharePoint List displayed in XML using OWSSVR.dll

OWSSVR.dll will, among other functions, return the XML data of a SharePoint List. The format of this utility is:

http://yourserver/yourweb/_vti_bin/owssvr.dll?Cmd=Display&List={guid}&XMLDATA=TRUE

http://webcs10.cgc.maricopa.edu/student-affairs/athletics/athletics/_vti_bin/owssvr.dll?Cmd=Display&List=5C1E1425%2D8F8E%2D4427%2D8B4A%2D1A97748B4AD6&XMLDATA=TRUE

More information can be found here:

http://msdn.microsoft.com/en-us/library/ms478653.aspx

Tuesday, January 4, 2011

Dynamically changing Frameset dimensions

There may be a need to dynamically change the dimensions of an HTML Frameset in the DigitalSignage system.

If we have a frameset defined:


<frameset id="mainFrame" border="0" rows="25%,70%,*">
<frame border="0" noresize="noresize" src="header.html" />
<frame src="" scrolling="no" frameborder="0" />
<frameset border="0" cols="25%,50%,*">
<frame src="footer1.html" scrolling="no" frameborder="0" />
<frame src="footer2.html" scrolling="no" frameborder="0" />
<frame src="weather.aspx" scrolling="no" frameborder="0" />
</frameset>
</frameset>

Below is an example of javascript that varies the dimensions of the rows:

parent.document.getElementById('mainFrame').rows='0%,95%,*';

With this code we're hiding the top row by setting the height to 0%.

Tuesday, December 14, 2010

TextBoxCounter control by skmControls

In programming a textarea for a web application, I had the need to display to the user the amount of characters to go before the maximum length of the textarea was reached. I found a .NET library on line called skmControls2.dll that provides a textBoxCounter control. Documentation can be found at:

http://scottonwriting.net/sowblog/codeprojects.htm

Below is an example of the use of the control with some of its properties:

TextBoxCounter tbc = new TextBoxCounter();
tbc.TextBoxControlId = commentBox.ID;
tbc.TreatCarriageReturnsAsOneCharacter =
true;
tbc.MaxCharacterLength = 500;
tbc.DataFormatString =
" Characters entered = {1}.";
tbc.CssClass =
"CharacterNorm";
tbc.WarningPercentage = 95;
tbc.CssClassForWarning =
"CharacterWarn";