Posts

Showing posts with the label Column Formatting

SharePoint 2010: How do I populate a lookup field in C#?

I had the requirement to populate seeddata in a simple list structure that contained some lookup columns. The lookup requires the identifier/display text of the source object - in my case it was a ParentItem that was being used in the ChildItem table. I created a lookup column 'Parent' and added it the child list. The following code resolved the problem. Please note that this code is for seed data that has expected values and does no validation checking or use any defensive programming. // Add items to the parent item SPList parentList = web.Lists["ParentItem"]; SPListItem item = parentList.Items.Add(); item["Title"] = "Parent Header 1"; item.Update(); // Add the child item SPList childList = web.Lists["ChildItem"]; item = childList.Items.Add(); SPListItem parentItem = GetHeaderItem(parentList, "Parent Header 1"); item["Title"] = "My Child Item"; item["Parent"] = new SPFieldLookupV...

SharePoint 2010: How can I change my Date column to display only the date (DateOnly)?

I thought this would be a piece of cake - open up  SharePoint Manager , get the XML and done. Unfortunately, that is not the case. The property DisplayFormat holds the value, and the XML produced seems fine but the field kept on displaying the time. I then saw  this article  from Microsoft with the answer - the XML element is Format, NOT DISPLAYFORMAT. Adding Format="DateOnly" to my field XML resolved the problem.