ListItem Constructor (String, String, Boolean)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Initializes a new instance of the ListItem class with the specified text, value, and enabled data.

Namespace:   System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)

public ListItem(
	string text,
	string value,
	bool enabled


Type: System.String

The text to display in the list control for the item represented by the ListItem.

Type: System.String

The value associated with the ListItem.

Type: System.Boolean

Indicates whether the ListItem is enabled.

The following table shows initial property values for an instance of ListItem.


Initial Value


The value of the text parameter.


The value of the value parameter.


The value of the enabled parameter.

The following example demonstrates adding items to and removing items from ListBox controls. When an item is selected in the ListBox1 control, a new ListItem control with the same value can be created and added to the ListBox2 control, if the ListBox2 control does not already contain an item with that text. In this example the constructor is called with enabled set to true. If it was called with enabled set to false, the new ListItem control would not appear in the ListBox control.


The following code sample uses the single-file code model and may not work correctly if copied directly into a code-behind file. This code sample must be copied into an empty text file that has an .aspx extension. For more information on the Web Forms code model, see ASP.NET Web Forms Page Code Model.

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="" >
    <title>ListItem Example</title>
<script runat="server">

         void AddBtn_Click(Object Sender, EventArgs e) 
             if (ListBox1.SelectedIndex > -1) 
                  if (ListBox2.Items.FindByText(ListBox1.SelectedItem.Text) == null) 
                     ListItem Item = new ListItem(ListBox1.SelectedItem.Text, 
                         ListBox1.SelectedItem.Value, true);

         void DelBtn_Click(Object Sender, EventArgs e) 
             if (ListBox2.SelectedIndex > -1) 



     <h3>ListItem Example</h3>
     <form id="form1" runat="server">
         <asp:ListBox id="ListBox1" Width="100px" runat="server">
             <asp:ListItem Value="Value 1">Item 1</asp:ListItem>
             <asp:ListItem Value="Value 2">Item 2</asp:ListItem>
             <asp:ListItem Value="Value 3">Item 3</asp:ListItem>
             <asp:ListItem Value="Value 4">Item 4</asp:ListItem>
             <asp:ListItem Value="Value 5" Selected="True">Item 5</asp:ListItem>
             <asp:ListItem Value="Value 6">Item 6</asp:ListItem>
         <asp:button Text="--->" OnClick="AddBtn_Click" runat="server" /><br />
         <asp:button Text="<---" OnClick="DelBtn_Click" runat="server" />
         <asp:ListBox id="ListBox2" Width="100px" runat="server"/>


.NET Framework
Available since 2.0
Return to top