Net-informations.com
SiteMap  | About    

DropDownList Control

The drop-down list can contain any number of items and allows the user to select a single item from the drop-down list.

dropdownlist-control

A default ListItem can be added to a DropDownList programmatically with the following syntax after binding data to the DropDownList:

vb.net

  DropDownList1.Items.Add("Sunday")

C#

  DropDownList1.Items.Add("Sunday");

The following ASP.NET program add seven days in a week to the DropDownList in the form load event and display the selected item in the button click event.

Default.aspx

  

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
	<title>Untitled Page</title>
</head>
<body>
	<form id="form1" runat="server">
	<div>
	   <asp:DropDownList ID="DropDownList1" runat="server">
       </asp:DropDownList>
	   &nbsp;
	   <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
	   &nbsp;
	   <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
	</div>
	</form>
</body>
</html>


Click the following links to see full source code

C# Source Code
VB.NET Source Code
default.aspx.cs
default.aspx.vb





net-informations.com (C) 2016    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.