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.

2 thoughts on “How to Add Column Descriptions to Your Custom Forms

  1. Pingback: Tweets that mention How to Add Column Descriptions to Your Custom Forms | SharePoint Fun -- Topsy.com

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

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">