Net-informations.com
SiteMap  | About    

Listbox Control

You can use the Add or Insert method to add items to a list box. Use the Rows property to specify the height of the control.

listbox-control

vb.net

  ListBox1.Items.Add("Sunday")

C#

  ListBox1.Items.Add("Sunday");

The Add method adds new items at the end of an unsorted list box. The Insert method allows you to specify where to insert the item you are adding.

Listbox control that allows single or multiple item selection.To enable multiple item selection, set the SelectionMode property to ListSelectionMode.Multiple.

vb.net

  ListBox1.SelectionMode = ListSelectionMode.Multiple

C#

  ListBox1.SelectionMode = System.Web.UI.WebControls.ListSelectionMode.Multiple;

The following ASP.NET program add seven days in a week to the ListBox in the load event and display the selected item in the label.

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:ListBox ID="ListBox1" runat="server"></asp:ListBox>
	   &nbsp;
	   <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
	   <br />
	   <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) 2017    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.