0 out of 1 rated this helpful - Rate this topic

SPHtmlSelect Class

Represents an HTML Select control, with extended behavior added by SharePoint. In addition to the normal behavior of the HTML Select control, SharePoint adds the ability to add or remove choices, move choices between SPHtmlSelect controls using buttons, and select multiple choices in multiple SPHtmlSelect controls. This control is intended to be used within a GroupedItemPicker control to represent the Select boxes.

System.Object
  System.Web.UI.Control
    System.Web.UI.HtmlControls.HtmlControl
      System.Web.UI.HtmlControls.HtmlContainerControl
        System.Web.UI.HtmlControls.HtmlSelect
          Microsoft.SharePoint.WebControls.SPHtmlSelect

Namespace:  Microsoft.SharePoint.WebControls
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: No
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public sealed class SPHtmlSelect : HtmlSelect
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
SPHtmlSelect
Description

The Microsoft.SharePoint.WebControls.SPHtmlSelect class inherits from the System.Web.UI.HtmlControls.HtmlSelect class which provides a control congruent to the fundamental HTML selection tags (<select> / <option>). Such tags are ordinary when constructing primitive selection options, common when no to little server-side logic is mandated.

The SPHtmlSelect class extends the HtmlSelect class by supplementing its behavior with custom JavaScript in order to provide proper SharePoint picker control support, as well as declarative design attributes (properties for declartive width and height). 

The Usage Scenario 

The customary usage of the SPHtmlSelect class is when coupled with the Microsoft.SharePoint.WebControls.GroupedItemPicker control. GroupedItemPicker has heavy internal SharePoint representation, however is also common when building custom SharePoint field types where an operation might target a user mutable collection of items. GroupedItemPicker provides a twin list box (literal list box elements and not control based) which allows items (Microsoft.SharePoint.WebControls.PickerItem objects) to be moved from one list box to another, while providing a supplementary property display of currently selected items. 

A SPHtmlSelect control can couple with GroupedItemPicker by assimilating GroupedItemPicker.CandidateControlId and GroupedItemPicker.ResultControlId properties in order to supply a exclusive control id to get a property typed SPHtmlSelect object.

In the below, I am demonstrating declaring a global GroupedItemPicker control and initializing it within a overriden CreateChildControls. Within the DemoCasting method, we are using the FindControl method to get a reference to the target list and casting it to a SPHtmlSelect object. Afterwards, any arbitrary operations could be performed with the created object. 

C# Code Example

private GroupedItemPicker _picker;
protected override void CreateChildControls()
{
base.CreateChildControls();
_picker = new GroupedItemPicker();
_picker.ID = "Picker";
DemoCasting();
}
private void DemoCasting()
{
SPHtmlSelect candidateSelect = (SPHtmlSelect)_picker.FindControl(_picker.CandidateControlId);
SPHtmlSelect resultSelect = (SPHtmlSelect)_picker.FindControl(_picker.ResultControlId);


Visual Basic .NET Code Example

Private _picker As GroupedItemPicker
Protected Overloads Overrides Sub CreateChildControls()
MyBase.CreateChildControls()
_picker = New GroupedItemPicker()
_picker.ID = "Picker"
DemoCasting()
End Sub
Private Sub DemoCasting()

Dim candidateSelect As SPHtmlSelect = DirectCast(_picker.FindControl(_picker.CandidateControlId), SPHtmlSelect)
Dim resultSelect As SPHtmlSelect = DirectCast(_picker.FindControl(_picker.ResultControlId), SPHtmlSelect)
End Sub