Create a custom field class by inheriting from SPFieldText class.
public class RelationshipField : SPFieldText {
// Methods
public RelationshipField(SPFieldCollection fields, string fieldName) : base(fields, fieldName) {}
public RelationshipField(SPFieldCollection fields, string typeName, string displayName) : base(fields, typeName, displayName)
{}
// Properties
public override BaseFieldControl FieldRenderingControl
{
get
{
BaseFieldControl control = new RelationshipFieldControl();
control.FieldName = base.InternalName;
return control;
}
}
}
Create a control class by inherting from BaseFieldControl class. and also need to include the following namespaces.
using Microsoft.SharePoint;
using Microsoft.SharePoint.Publishing.WebControls;
using Microsoft.SharePoint.WebControls;
Here is how the control creation goes:
public class RelationshipFieldControl : BaseFieldControl
{
protected AssetUrlSelector urlSelector;
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
// Set the value if this is a postback.
if (this.Page.IsPostBack && base.ControlMode == SPControlMode.Edit)
{
this.ListItemFieldValue = urlSelector.AssetUrl;
}
}
protected override void CreateChildControls()
{
base.CreateChildControls();
// Add the asset picker when in edit mode.
if (base.ControlMode == SPControlMode.Edit)
{
urlSelector = new AssetUrlSelector();
this.Controls.Add(urlSelector);
}
}
protected override void Render(HtmlTextWriter output)
{
// If this is edit mode and has a value, set the picker.
if (base.ControlMode.Equals(SPControlMode.Edit)
&& this.ListItemFieldValue != null)
{
this.urlSelector.AssetUrl = this.ListItemFieldValue.ToString();
}
base.Render(output);
}
}
To register the custom field created above, you need to create a field type definition file as show below. And this xml file needs to be copied to 12\TEMPLATE\XML directory to recognize by MOSS.
asdf
asd
fa
sdf
afwasre
asraqer
Happy Coding... !!
~ Gangadhar Kotu
No comments:
Post a Comment