in simple word every one is asking the same question
"How to hide a column of SharePoint list in different mode (Add / Edit / Display 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.
Check the code snippet first
SPSite objSite = SPContext.Current.Site;
SPWeb objWeb = objSite.OpenWeb();
SPList objList = objWeb.Lists[“Name of the list”];
SPField objField = objList.Fields[“Name of the column”];
This SPField has following properties.
objField.ShowInDisplayForm //show in display mode(dispform.aspx)
objField.ShowInEditForm //show in edit mode(editform.aspx)
objField.ShowInListSettings //show in list setting page of list where u can set order or remove that field.
objField.ShowInNewForm //show in new form (newform.aspx)
objField.ShowInVersionHistory // displayed in the page for viewing list item versions. objField.ShowInViewForms //show in grid view
All the properties shows their setting meaning by their name.
Just set the properties you want and uodate field and list.
See the magic.
Another problem is after hiding column how to set its data?
In event handler / item handler you can use
properties.AfterProperties[“Internal name of that column”] = “assign text”;
You will get your result.
Only thing to keep in mind that
If column is hidden then u cannot retrieve its value.
Some time it will show error
“One or more field types are not installed properly. Go to the list settings page to delete these fields.”
If you get these error there is only two scenarios is there.
1) If you have any custom field then it was not properly installed.
2) If you have do not have the field with that name and you are assigning value to it.
Just do a due diligence and check this two scenarios and your error might be solved.