Share via


HtmlHelper.DropDownList Method (String, IEnumerable<SelectListItem>, Object)

Returns an HTML drop-down list control that has the specified name and custom attributes defined by an attribute object, and that contains the specified list items.

Namespace:  System.Web.WebPages.Html
Assembly:  System.Web.WebPages (in System.Web.WebPages.dll)

Syntax

'Declaration
Public Function DropDownList ( _
    name As String, _
    selectList As IEnumerable(Of SelectListItem), _
    htmlAttributes As Object _
) As IHtmlString
'Usage
Dim instance As HtmlHelper 
Dim name As String 
Dim selectList As IEnumerable(Of SelectListItem)
Dim htmlAttributes As Object 
Dim returnValue As IHtmlString 

returnValue = instance.DropDownList(name, _
    selectList, htmlAttributes)
public IHtmlString DropDownList(
    string name,
    IEnumerable<SelectListItem> selectList,
    Object htmlAttributes
)
public:
IHtmlString^ DropDownList(
    String^ name, 
    IEnumerable<SelectListItem^>^ selectList, 
    Object^ htmlAttributes
)
member DropDownList : 
        name:string * 
        selectList:IEnumerable<SelectListItem> * 
        htmlAttributes:Object -> IHtmlString
public function DropDownList(
    name : String, 
    selectList : IEnumerable<SelectListItem>, 
    htmlAttributes : Object
) : IHtmlString

Parameters

  • name
    Type: System.String
    The value to assign to the name attribute of the HTML select element.
  • htmlAttributes
    Type: System.Object
    An object that contains custom attributes for the element. The attribute names and values are retrieved through reflection by examining the properties of the object.

Return Value

Type: System.Web.IHtmlString
The HTML markup that represents the drop-down list 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:

<select name="name" ...htmlAttributes...>
  <option value="selectList[0].Value">selectList[0].Text</option>
  <option value="selectList[1].Value">selectList[1].Text</option>
  ...
</select>

See Also

Reference

HtmlHelper Class

DropDownList Overload

System.Web.WebPages.Html Namespace