Hi Liam,
This is for form control(built Type fields). I had providing sample code for reference
<asp:ListBox ID="drpColor" runat="server" SelectionMode="Multiple" CssClass="filter-multi-select">
<asp:ListItem Text="Red" Value="#FF0000"></asp:ListItem>
<asp:ListItem Text="Green" Value="#008000"></asp:ListItem>
<asp:ListItem Text="Blue" Value="#0000FF"></asp:ListItem>
<asp:ListItem Text="Yellow" Value="#FFFF00"></asp:ListItem>
</asp:ListBox>
public partial class CMSFormControls_ColorSelector : FormEngineUserControl
{
private string selectedColorValue = string.Empty;
/// <summary>
/// Gets or sets the value entered into the field, a hexadecimal color code in this case.
/// </summary>
public override object Value
{
get
{
return selectedColorValue;
}
set
{
EnsureItems();
foreach (ListItem color in drpColor.Items)
{
if (color.Selected && string.IsNullOrEmpty(selectedColorValue))
{
selectedColorValue = color.Value;
}
else if (color.Selected)
{
selectedColorValue = selectedColorValue + "," + color.Value;
}
}
drpColor.SelectedValue = selectedColorValue;
}
}
/// <summary>
/// Property used to access the Width parameter of the form control.
/// </summary>
public int SelectorWidth
{
get
{
return ValidationHelper.GetInteger(GetValue("SelectorWidth"), 0);
}
set
{
SetValue("SelectorWidth", value);
}
}
//
// Summary:
// Returns an array of values of any other fields returned by the control.
//
// Remarks:
// It returns an array where first dimension is attribute name and the second dimension
// is its value.
public override object[,] GetOtherValues()
{
object[,] array = new object[1, 2];
array[0, 0] = "ProductColor";
string selectedColors = string.Empty;
foreach(ListItem color in drpColor.Items)
{
if(color.Selected && string.IsNullOrEmpty(selectedColors))
{
selectedColors = color.Text;
}
else if (color.Selected)
{
selectedColors = selectedColors + "," + color.Text;
}
}
array[0, 1] = selectedColors;
return array;
}
/// <summary>
/// Returns true if a color is selected. Otherwise, it returns false and displays an error message.
/// </summary>
public override bool IsValid()
{
if ((string)Value != "")
{
return true;
}
else
{
// Sets the form control validation error message
this.ValidationError = "Please choose a color.";
return false;
}
}
/// <summary>
/// Sets up the internal DropDownList control.
/// </summary>
protected void EnsureItems()
{
// Applies the width specified through the parameter of the form control if it is valid
if (SelectorWidth > 0)
{
drpColor.Width = SelectorWidth;
}
}
/// <summary>
/// Handler for the Load event of the control.
/// </summary>
protected void Page_Load(object Sender, EventArgs e)
{
// Initializes the drop-down list options
if (!IsPostBack)
{
EnsureItems();
}
}
}