您的位置:首页 > 编程语言 > ASP

HTML Controls->ASP.NET HtmlSelect Control

2007-03-26 15:36 489 查看

Definition and Usage

The HtmlSelect control is used to control a <select> element. In HTML, the <select> element is used to create a drop-down list.

Properties

PropertyDescription
AttributesReturns all attribute name and value pairs of the element
DataMemberA name of a data table to use
DataSourceA data source to use
DataTextFieldA field in the data source to be displayed in the drop-down list
DataValueFieldA field in the data source that specifies the value of each selectable item in the drop-down list
DisabledA Boolean value that indicates whether or not the control should be disabled. Default is false
idA unique id for the control
InnerHtmlSets or returns the content between the opening and closing tags of the HTML element. Special characters are not automatically converted to HTML entities
InnerTextSets or returns all text between the opening and closing tags of the HTML element. Special characters are automatically converted to HTML entities
ItemsThe list of items in the drop-down list
MultipleWhether multiple items can be selected at a time
OnServerChangeThe name of the function to be executed when the selected item has changed
runatSpecifies that the control is a server control. Must be set to "server"
SelectedIndexThe index of the currently selected item
SizeThe number of visible items in the drop-down list
StyleSets or returns the CSS properties that are applied to the control
TagNameReturns the element tag name
ValueThe value of the currently selected item
VisibleA Boolean value that indicates whether or not the control should be visible

Examples

HTMLSelect

<script runat="server">
Sub choose_image(Sender As Object, e As EventArgs)
image1.Src = select1.Value
End Sub
</script>

<html>
<body>

<form runat="server">
<select id="select1" runat="server">
<option value="smiley.gif">Smiley</option>
<option value="angry.gif">Angry</option>
<option value="stickman.gif">Stickman</option>
</select>
<input type="submit" runat="server" value="Display image"
OnServerClick="choose_image">
<br /><br />
<img id="image1" src="smiley.gif" runat="server" width="32" height="32" />
</form>

</body>
</html>
Output Result:

Smiley
Angry
Stickman


IF you click the selectbox "angry", it will shows :

Smiley
Angry
Stickman


In this example we declare an HtmlImage and an HTMLSelect control in an .aspx file (remember to embed the controls inside an HtmlForm control). Then we modify the src property of the HtmlImage control based on user choices. The value selected in the HtmlSelect control determines which image to display.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: