.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Articles >> SharePoint >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Hide Columns In SharePoint List On New, Edit And Disp Forms

Posted By:Sunil Yadav       Posted Date: May 26, 2010    Points: 10    Category: SharePoint    URL: http://www.dotnetspark.com  

I this article i am going to sho how we can hide Columns In SharePoint list on new, edit and disp forms.
 

There are situation in which we only need to show some column when creating New Item,Editing Item or Displaying Item.
Following are the way to do that..

Using C# Code

         
SPSite site = new SPSite("http://mossserver/");
SPWeb web = site.OpenWeb();
SPList selectedList = web.Lists["Pentest Report"];
selectedList.Fields["Affected Url"].ReadOnlyField = true;
selectedList.Fields["Affected Url"].Update();
selectedList.Fields["Description"].ReadOnlyField = true;
selectedList.Fields["Description"].Update();

Using powershell

function HideFormField([string]$url, [string]$List, [string]$Field) {
  [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")

  $SPSite = New-Object Microsoft.SharePoint.SPSite($url)
  $OpenWeb = $SPSite.OpenWeb()
  $OpenList = $OpenWeb.Lists[$List]
  $OpenField = $OpenList.Fields[$Field]
  $OpenField.ShowInNewForm = $False
  $OpenField.ShowInEditForm = $False
  $OpenField.Update()
  $SPSite.Dispose()
  $OpenWeb.Dispose()
}
You can call it in following manner.

HideFormField -url http://mossserver -List "My Task" -Field "Title"


Using JavaScript


A simple javascript function ca do all you work.You just need to find the control and apply a style with display property to 'None'.

style="display:none"

For more info follow the link below..

http://sharepointsherpa.com/2008/08/26/sharepoint-2007-hiding-fields-on-newformaspx-and-editformaspx-the-easy-way/

 Subscribe to Articles

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend