Blogger

  • This email address is being protected from spambots. You need JavaScript enabled to view it.

    Recent items

Login

If you use this field to render a lookup field, the results is an hyperlink to view the related item.

Show/Hidden csharp code

View source
 
 
 
<SharePointWebControls:FieldValue ID="lfYear" FieldName="Year" runat="server"/>
 
 
 


If you want to create a reusable WebControl just to render the Lookup Value, you can copy and paste this code and reproduce these steps:

  • Create the web control. The property FieldName would be used to retreive the date from the SPListItem

Show/Hidden csharp code

View source
 
 
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint.Publishing.WebControls;
using Microsoft.SharePoint.Publishing.Internal.WebControls;
using System.Text.RegularExpressions;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Web.UI;
using Microsoft.SharePoint;
 
namespace LucaCostante.com.WebControls
{
    public class SimpleLookupView: WebControl
    {
        private string name;
        [Bindable(true), DefaultValue(""), Localizable(false)]
        public string FieldName
        {
            get { return name; }
            set { name = value; }
        }
 
        protected override void Render(HtmlTextWriter writer)
        {
            try
            {
                string value = GetLookupValue(FieldName);
                if (SPContext.Current.ListItem.Fields.ContainsFieldWithStaticName(FieldName))
                    value=SPContext.Current.Item[FieldName].ToString();
 
                if (!string.IsNullOrEmpty(value) && value.Contains(";#"))
                    value=value.Split(new string[]{";#"},StringSplitOptions.RemoveEmptyEntries)[1];
                writer.Write(value);
            }
            catch { }
        }
 
        public static string GetLookupValue(string fieldName)
        {
            string value = string.Empty;
            if (SPContext.Current.Item.Fields.ContainsFieldWithStaticName(fieldName))
                value = SPContext.Current.Item[fieldName].ToString();
 
            if (!string.IsNullOrEmpty(value) && value.Contains(";#"))
                value = value.Split(new string[] { ";#" }, StringSplitOptions.RemoveEmptyEntries)[1];
 
            return value;
        }
    }
}
 

  • Register the WebControl into the PageLayout

Show/Hidden csharp code

View source
 
 
 
<%@ Register Tagprefix="LCWebControls" Namespace="LucaCostante.com.WebControls" Assembly="LucaCostante.com, Version=1.0.0.0, Culture=neutral, PublicKeyToken=13f47470cb97767e"%>
 
 
 

  • Use the web control

Show/Hidden csharp code

View source
 
 
 
<LCWebControls:SimpleLookupView ID="lfYear" FieldName="Year" runat="server" />
 
 
 

 

Published in SharePoint

Today I found a problem with the LOOKUPFIELD within a page layout during the edit mode.

This is the field definition

Show/Hidden html5 code

View source
 
 
 
<SharepointWebControls:LookupField FieldName="PL_Model" ID="PL_Model" runat="server" >
 
 
 

As defined with the above code, I have a Lookup fielt to a SharePoint List and when the count is greater than 20 items I'm not able to select any item from the combo box (see the image below).

 

This email address is being protected from spambots. You need JavaScript enabled to view it. helped me to find a solution. He told me that he had the same problem a few months ago. The solution is to add the InDesign = "true" attribute to the field definition into the page layout.

Show/Hidden html5 code

View source
 
 
 
<SharepointWebControls:LookupField FieldName="PL_Model" ID="PL_Model" runat="server" InDesign="true"/>
 
 
 

Now the combo box works fine and I can select my item :)

Published in SharePoint