Thursday, June 26, 2008

Sharepoint Custom DateTimeField control

I don't know if anyone has worked on the DateTimeField sharepoint control to display the value associated with it.

I searched a lot in blogs and google for this BUG from Microsoft till 07 Apr 2008 because thats when i have to write my own custom control. You can't use the datetimefield in SPControlMode.Display.

Here it goes:


public class myDateTime : DateTimeField
{
protected override void RenderFieldForDisplay(HtmlTextWriter output)
{
if (base.ControlMode == SPControlMode.Display)
{
if (base.ItemFieldValue != null)
output.Write(((DateTime)base.ItemFieldValue).ToShortDateString());
}
else
{
base.RenderFieldForDisplay(output);
}
}
}

Hey do post some comment if it helps you anyway !!

No comments: