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

Web Server Controls->ASP.NET DropDownList Control

2007-03-27 09:11 573 查看

Definition and Usage

The DropDownList control is used to create a drop-down list.

Each selectable item in a DropDownList control is defined by a ListItem element!

Tip: This control supports data binding!

Properties

PropertyDescription
AutoPostBackA Boolean value that specifies whether the form should be posted immediately after one of the items changes select status or not. Default is false
BorderColorSpecifies the color of the border around the drop-down list
BorderStyleSpecifies the style of the border around the drop-down list
BorderWidthSpecifies the width of the border around the drop-down list
DataSourceThe 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
idA unique id for the control
OnSelectedIndexChangedThe name of the function to be executed when the index of the selected item has changed
runatSpecifies that the control is a server control. Must be set to "server"

Examples

DropdownList
ASPX Source:

<script runat="server">
Sub submit(sender As Object, e As EventArgs)
mess.Text="You selected " & drop1.SelectedItem.Text
End Sub
</script>

<html>
<body>

<form runat="server">
<asp:DropDownList id="drop1" runat="server">
<asp:ListItem>Item 1</asp:ListItem>
<asp:ListItem>Item 2</asp:ListItem>
<asp:ListItem>Item 3</asp:ListItem>
<asp:ListItem>Item 4</asp:ListItem>
<asp:ListItem>Item 5</asp:ListItem>
<asp:ListItem>Item 6</asp:ListItem>
</asp:DropDownList>
<asp:Button Text="Submit" OnClick="submit" runat="server"/>
<p><asp:label id="mess" runat="server"/></p>
</form>

</body>
</html>
Output Result:

Item 1
Item 2
Item 3
Item 4
Item 5
Item 6

IF you click the DropDownList "Item 6"and then click the button "Submit",it will show:

Item 1
Item 2
Item 3
Item 4
Item 5
Item 6

You selected Item 6

In this example we declare one DropDownList control in an .aspx file. Then we create an event handler for the Click event which displays some text and the selected item, in a Label control.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: