List Column

How to hide a column of SharePoint list in different mode (Add / Edit / Display Mode)?

Posted on Updated on

Most of the time we have requirement like that this field should be shown only in new mode or it should not be shown only in Edit mode not in new mode.

We can hide it in view by not to show in grid view but what to do if you do not want to see that field in Dispforms.aspx?

Here is the way how to do that.
Option: 1
OBJECT MODEL

SPSite site = new SPSite(”http://Server:3000/”);
SPWeb web = site.OpenWeb();
web.AllowUnsafeUpdates = true;
SPList list = web.Lists[”Sample”];
SPField objField = list.Fields[”Sample1″];
objField.ShowInNewForm = true;
objField.ShowInDisplayForm = false;
objField.ShowInEditForm = true;
objField.Update();
list.Update();

Option: 2
List Definition
You can hide column appearing in New/Edit/View/ form by creating custom list defination for the list.

For creating custom list defination you can refer following MSDN link:
http://msdn.microsoft.com/en-us/library/ms466023.aspx

Now to hide a column from New/Edit/View/ form, you need to update content types of your list schema. Following is steps to do this (Assuming you have created custom list defination, following the steps mentioned in above URL):
1. Open schema.xml from your custom feature folder
2. Locate Content Types XML node, under that locates the Field which you want to hide from Edit form, set the ShowInEditForm value to FALSE.

Following example hides the Title column of custom list appearing in Edit form:

<FieldRef ID=”{fa564e0f-0c70-4ab9-b863-0177e6ddd247}” Name=”Title” Required=”TRUE” ShowInNewForm=”TRUE” ShowInEditForm=”FALSE” />

Advertisement