HtmlHelper.ListBox Method (String, String, IEnumerable<SelectListItem>, Object, Int32, Boolean)
Returns an HTML list box control that has the specified name, size, items, default item, and selections, and that specifies whether multiple selections are enabled.
Namespace: System.Web.WebPages.Html
Assembly: System.Web.WebPages (in System.Web.WebPages.dll)
Syntax
'Declaration
Public Function ListBox ( _
name As String, _
defaultOption As String, _
selectList As IEnumerable(Of SelectListItem), _
selectedValues As Object, _
size As Integer, _
allowMultiple As Boolean _
) As IHtmlString
'Usage
Dim instance As HtmlHelper
Dim name As String
Dim defaultOption As String
Dim selectList As IEnumerable(Of SelectListItem)
Dim selectedValues As Object
Dim size As Integer
Dim allowMultiple As Boolean
Dim returnValue As IHtmlString
returnValue = instance.ListBox(name, defaultOption, _
selectList, selectedValues, size, _
allowMultiple)
public IHtmlString ListBox(
string name,
string defaultOption,
IEnumerable<SelectListItem> selectList,
Object selectedValues,
int size,
bool allowMultiple
)
public:
IHtmlString^ ListBox(
String^ name,
String^ defaultOption,
IEnumerable<SelectListItem^>^ selectList,
Object^ selectedValues,
int size,
bool allowMultiple
)
member ListBox :
name:string *
defaultOption:string *
selectList:IEnumerable<SelectListItem> *
selectedValues:Object *
size:int *
allowMultiple:bool -> IHtmlString
public function ListBox(
name : String,
defaultOption : String,
selectList : IEnumerable<SelectListItem>,
selectedValues : Object,
size : int,
allowMultiple : boolean
) : IHtmlString
Parameters
- name
Type: System.String
The value to assign to the name attribute of the HTML select element.
- defaultOption
Type: System.String
The text to display for the default option in the list.
- selectList
Type: System.Collections.Generic.IEnumerable<SelectListItem>
A list of SelectListItem instances that are used to populate the list.
- selectedValues
Type: System.Object
An object that specifies the items in the list that are selected by default. The selections are retrieved through reflection by examining the properties of the object.
- size
Type: System.Int32
The value to assign to the size attribute of the element.
- allowMultiple
Type: System.Boolean
true to indicate that multiple selections are enabled; otherwise, false.
Return Value
Type: System.Web.IHtmlString
The HTML markup that represents the list box control.
Exceptions
Exception | Condition |
---|---|
ArgumentException | name is null reference (Nothing in Visual Basic) or empty. |
Remarks
The returned markup consists of an HTML select element in the following form:
|
allowMultiple is true. |
|
allowMultiple is false. |
A list item is selected when either its value or its displayed text (if the item has no value) matches one of the properties of selectedValues, which are examined through reflection. When an item is selected, the selected attribute of the associated HTML option element is set to selected.
The size attribute specifies the number of list items that are visible in the list box. If size is greater than 1 and more items are available than can be displayed, the list box displays scroll bars.