Posts

Showing posts from September, 2012

SharePoint Designer Adds Blank Rows

Sometimes I have seen SharePoint Designer add lots of blank rows when you save an .aspx file. In trying to discern how this happens, I noticed a pattern and when I made a change the program no longer added lots of blank rows in the code. The behavior appears to happen when you have text, such as an attribute, which is not surrounded on either side by at least an open or close tag. Without showing code, just look for a value like a javascript: or an option in a data view which is not surrounded by tags and thus is considered plain text (black) in code view, and for some reason the automatic formatting engine starts placing way too many blank lines in there (I have seen tens of thousands).

Bind a DropDown ASP Control to a Data View and Filter It

Place your page into design view Click Task panes :: Data Source LibraryClick the data source called CategoriesClick to Insert Data Source ControlIf prompted, click “Yes” to display the control Place insertion point below this control Click Insert :: ASP.NET Controls > Drop Down ListClick the Smart Panel :: Choose Data Source...Choose the Data Source (for example, SPListDataSource1) Tell it to display "CategoryName" (or the field that contains your category name) Make its value "CategoryName" Click OKClick to select the dropdownlist control Click the Smart Panel :: AutoPostBack == TrueDrag and drop the Products list onto a page to create a Data View Click the Smart Panel :: Edit Columns to add and remove the columns you want to display Click Data View :: FilterCreate the following filter:
Field: CategoryName (or the field that contains your category name)
Comparison: Equals
Value: [Create a new Parameter]
Param Name: Param1
Source: Control
Control ID: DropDow…

Formatting DateTime in XSL Data View

The default styles for XSL datetime does not include all that is possible. The easiest way to format it is to click on the element in Design view, so that it shows the available formats for Date and for Time. Once you select something else, it will change the number in the FormatDateTime function from 5 to something like: 'M/d/yyyy HH:mm:ss' Now you can see what is possible. I needed to get a military time output, so I removed the colons and the seconds from the time. <xsl:value-of select="ddwrt:FormatDateTime(string(@TimeIncident) ,1033, 'M/d/yyyy HHmm')"/> You can search this page for instructions on what character combinations are possible for dates and times: http://msdn.microsoft.com/en-us/library/az4se3k1.aspx

Building a Drop-Down menu in DataView Edit Template

The important things are:The ID must be unique, this is usually the ff1 style name.The beginning of the DataBind must have ‘u’ for an edit, I assume this means update.  Sometimes it may say ‘I’, this is for new or insert commands.<SharePoint:FormField runat=”server” id=”ff1{$Pos}” ControlMode=”Edit” FieldName=”ChoiceColumn” ItemId=”{@ID}” __designer:bind=”{ddwrt:DataBind(‘u’,concat(‘ff1’,$Pos),’Value’,’ValueChanged’,’ID’,ddwrt:EscapeDelims(string(@ID)),’@ChoiceColumn’)}”/>Remember that ff1{$Pos} and ‘ff1’ in the DataBind must be changed and match each other within the control.  ff1 can be changed to anything without spaces.  Also the FieldName=”ChoiceColumn” should match the proper name you have for the column and the DataBind should match the @ name for the column.

Popup window to a data field from a DataView

A request was made to have a list shown in a dashboard view with bubbles for certain statuses. Red, Yellow, Green, and White. When the user clicks on Red or Yellow the Comments field for the list should popup in a new window showing only the comments. 1. Create a new custom list form in SharePoint Designer in the same folder as the other views. Go to the lists folder and then the folder for the list, create a new blank aspx page. I named mine: comments.aspx. In the form tag insert a custom list form. (Insert --> SharePoint Controls --> Custom List Form) Choose the list, uncheck the toolbar, and select the view layout. This will create a form with all of the fields. You must delete any you do not want. In this case I removed everything except the Comments field, I rearranged the layout so the title and the data are on separate rows, thus allowing the comments title to be above and centered over the data in the list. I then removed the toolbar rows and the footer rows with the…

JavaScript - Using the window.open method

​The syntax of the window.open method is given below:
window.open(URL, windowName[, windowFeatures])URL
The URL of the page to open in the new window. This argument could be blank. windowName
A name to be given to the new window. The name can be used to refer this window again. windowFeatures
A string that determines the various window features to be included in the popup window (like status bar, address bar etc.)
The following code opens a new browser window with standard features. window.open ("http://www.javascript-coder.com","mywindow")Changing the features of the PopupYou can control the features of the popup using the last argument to the window.open method. The following code opens a window with a status bar and no extra features: window.open ("http://www.javascript-coder.com","mywindow","status=1");The code below opens a window with toolbar and status bar: window.open ("http://www.javascript-coder.com", "mywindow"…

Attachments view for DataView webpart

Use this for Single List Item View:<SharePoint:AttachmentsField ControlMode=”Display” EnableViewState=”true” FieldName=”Attachments” runat=”server”/> Use this for Multiple List item View:<SharePoint:AttachmentButton ControlMode=”Edit” Enabled=”true” runat=”server” Visible=”false”/><SharePoint:AttachmentsField ControlMode=”Display” EnableViewState=”true” FieldName=”Attachments” runat=”server”/>

XSL test for NULL

​I had problems trying to test for NOT NULL so I can choose one value or another depending on whether something is NULL. Case: Show the value of Date1. But if Date1 is NULL, show the value of Date2. If both exist, show Date1 of course. NULL is found in SharePoint XSL by testing for an empty value, which is simply referenced as two single quotes with nothing in between. test <xsl:choose> <xsl:when test="@Date1=''"><xsl:value-of select="ddwrt:FormatDate(string(@Date2), 1033, 5)"></xsl:when> <xsl:otherwise>"><xsl:value-of select="ddwrt:FormatDate(string(@Date1), 1033, 5)"></xsl:otherwise></xsl:choose> So here you see if the value of Date1 is null, show Date2, else show Date1.

Style SharePoint Breadcrumbs

Until I realized that the breadcrumbs control is always styled by a class called ms-titlearea I was not able to do any styling that worked. So override this style by placing it in an attached stylesheet or inline in the page. Here is the required styles and how I styled them the last time. <style type="text/css"> .ms-titlearea a { color:#3966bf; text-decoration:none;} .ms.titlearea a:hover { color:#FFF; text-decoration:underline;} <td style="vertical-align:top;width:35%" class="ms-titlearea"> <div class="BreadcrumbText"> <p style="margin-top:6px;"> <asp:SiteMapPath SiteMapProvider="SPContentMapProvider" id="ContentMap" SkipLinkText="" runat="server"/></p></div></td>

DataView webpart - Creating Title Hyperlink and returning back to dataview

To create a hyperlink on a field, and also have it redirect to the page you hyperlinked from, use this format: <td>
    <a href=http://northwindtraders/Lists/Products/EditForm.aspx?ID={@ID} onclick="GoToLink(this);return false;" target="_self">
        <xsl:value-of select="@Product_x0020_Name" />
    </a>
</td>

DataView webpart - Formatting alternating rows

​I like to format everything in a data view webpart. It is tricky to get the alternating rows formatting to work correctly. Here is an example that is working: You must remove the <xsl:variable name="dvt_StyleName">[stylename]<xsl:variable> tag so that we can assign a class to the table and style it our way. For some reason the xsl style does not work as expected. Note: the entire page is styled with a dark background, #212121, so this is why I style the table with a white background. Styles:.DVTable { background-color:white; color:black;} .DVDashboardCellAlternatingDark { background-color:#CCCCCC;} Add the DVTable to the table just before the headings <th> tags. I actually replace the <th> tags with my own <td> tags and style the cell for a good background and the span tag for text effects. Now we need to replace the style that is applied when the <xsl:if test="position() mod 2 = 1"> is run (this tests to see if the row is an od…