How to Add Column Descriptions to Your Custom Forms

This is a quick overview on how to add a column’s description to your custom edit and disp forms in SharePoint 2007.

List Name: Projects
Column Name: Status
Column Type: Lookup
Column Description: “Choose the status for this current project.”

To add a column to a form and display it’s contents, it’s pretty straight forward:

SPWeb web = SPContext.Current.Web;
SPList projects = web.Lists["Projects"];
SPListItem item = projects.GetItemById(Convert.ToInt32(Request.QueryString["ID"]));
 
// use this to grab the value, you can get either the ID or the Value in the column
SPFieldLookupValue status = new SPFieldLookupValue(Convert.ToString(item["Status"]));
lblStatus.Text = status.LookupValue;
 
// use this to grab the columns description, or any other property for that column
SPFieldLookup statusDesc = new SPFieldLookup(projects.Fields, "Status");
lblStatusDesc.Text = statusDesc.Description;

The above works great, but please note that the column name for the SPFieldLookup method requires the SharePoint Internal Field Name. So for example, if your column name was Project Status, and you created the column with the spaces, then it will be Project_x0020_Status.

Trackbacks/Pingbacks

  1. Tweets that mention How to Add Column Descriptions to Your Custom Forms | SharePoint Fun -- Topsy.com - April 13, 2010

    […] This post was mentioned on Twitter by SharePoint Buzz, SharePoint Buzz. SharePoint Buzz said: #SharePoint How to Add Column Descriptions to Your Custom Forms: This is a quick overview on how to add a column’s… http://bit.ly/cDACDw […]

  2. Links (4/27/2010) « Steve Pietrek-Everything SharePoint/Silverlight - April 27, 2010

    […] How to Add Column Descriptions to Your Custom Forms […]

Leave a Reply