Search

Saturday, September 14, 2013
2 comments

How to use ListBox Control in ASP.NET

8:18 AMSaturday, September 14, 2013

The ListBox Control

The List control is a standard Web server control used to select one or more items from a list of items on a web page at runtime.
you can use the Rows property of the ListBox control to specify the height of the control. To enable muliple item selection you can set selection Mode property to ListSelectionMode. Multiple. you can find the
selection item in a single-selection ListBox control with the help of SelectedItem and SelectedIndex
properties. The SelectedItem property returns the  selection item as a List item object, which supports Text,
value and ListBox control and returns each as a List Box controls, the loop runs over the selected item
in the List Box controls and returns each selected item as a ListItem object by using the selectedIndex property.
This ListBox class inherits the :ListControl class and does not have any non-inherited events. The ListControl class does not have any non-inherited methods either. Note that the Items property of the ListControl class returns a collection of ListItem Objects which you can use to access an item in a ListBox.

Lets take a simple example of How to use ListBox Control.

In this example we will show that how to bind ListBox Control using Items collection property
Step-1 : Drop ListBox Control to Design window
Step-2 : Select Edit item using Show smart tag or you can use Items collection property for adding item to the ListBox
How to use ListBox Control in ASP.NET
Step-3 : Add item using ListItem Collection Editor
How to use ListBox Control in ASP.NET

Complete Code

<%@ Page Language="C#" %>

<!DOCTYPE html>

<script runat="server">

</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ListBox ID="ListBox1" runat="server" AutoPostBack="True">
            <asp:ListItem>Apple</asp:ListItem>
            <asp:ListItem>Mango</asp:ListItem>
            <asp:ListItem>Orange</asp:ListItem>
        </asp:ListBox>
    </div>
    </form>
</body>
</html>


Output
How to use ListBox Control in ASP.NET

Protected by Copyscape Online Copyright Protection Software

2 comments :

  1. Asp.Net listbox operations

    http://asp.net-informations.com/webcontrols/asp-net-listbox.htm

    ling

    ReplyDelete

 
Toggle Footer
Top