Web Server Controls->ASP.NET ListBox Control
2007-03-27 09:34
531 查看
Definition and Usage
The ListBox control is used to create a single- or multi-selection drop-down list.Each selectable item in a ListBox control is defined by a ListItem element!
Tip: This control supports data binding!
Properties
Property | Description |
---|---|
AutoPostBack | A Boolean value that specifies whether the form should be posted immediately after the index of the selected item has changed or not. Default is false |
BorderColor | Specifies the color of the border around the drop-down list |
BorderStyle | Specifies the style of the border around the drop-down list |
BorderWidth | Specifies the width of the border around the drop-down list |
DataSource | The data source to use |
DataTextField | A field in the data source to be displayed in the drop-down list |
DataValueField | A field in the data source that specifies the value of each selectable item in the drop-down list |
id | A unique id for the control |
OnSelectedIndexChanged | The name of the function to be executed when the index of the selected item has changed |
Rows | Specifies the height of the control |
runat | Specifies that the control is a server control. Must be set to "server" |
SelectionMode | Allows single or multiple selections. Legal values: "single" and "multiple". Default is "single" |
Examples
ListboxASPX 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:ListBox id="drop1" rows="3" runat="server"> <asp:ListItem selected="true">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:ListBox> <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 select the ListBox "Item 6" and the click the button "Submit",It will show:
Item 1 Item 2 Item 3 Item 4 Item 5 Item 6 You selected Item 6 |
相关文章推荐
- Web Server Controls->ASP.NET Image Control
- Web Server Controls->ASP.NET ImageButton Control
- Web Server Controls->ASP.NET RadioButton Control
- Web Server Controls->ASP.NET CheckBox Control
- Web Server Controls->ASP.NET Label Control
- Web Server Controls->ASP.NET RadioButtonList Control
- Web Server Controls->ASP.NET LinkButton Control
- Web Server Controls->ASP.NET Literal Control
- Web Server Controls->ASP.NET TableCell Control
- Web Server Controls->ASP.NET XML Control
- Web Server Controls->ASP.NET AdRotator Control
- Web Server Controls->ASP.NET DropDownList Control
- Web Server Controls->ASP.NET TableRow Control
- Web Server Controls->ASP.NET HyperLink Control
- Web Server Controls->ASP.NET Panel Control
- Web Server Controls->ASP.NET Table Control
- Web Server Controls->ASP.NET Button Control
- Web Server Controls->ASP.NET PlaceHolder Control
- Web server Controls->ASP.NET TextBox Control
- ASP.NET Web server controls