In asp.net 2.0, you can hide an item in listbox, such
ListItem item = new ListItem (text, value, enabled );
Of course, you can also use
Item. Enabled = false;
Although hidden in the Page, you can still use code to access the hidden options. The following is an example <% @ Page Language = "C #" %>
<Script runat = "server">
Protected void Page_Load (object sender, EventArgs e)
{
If (! Page. IsPostBack)
{
ListItem [] items = new ListItem []
{
New ListItem ("Item 1", "Value 1 "),
New ListItem ("Item 2", "Value 2", false ),
New ListItem ("Item 3", "Value 3 "),
New ListItem ("Item 4", "Value 4 ")
};
ListBox1.Items. AddRange (items );
}
}
Protected void button#click (object sender, EventArgs e)
{
Foreach (ListItem item in ListBox1.Items)
{
Response. Write (item. Text + "enabled =" + item. Enabled + "<br> ");
}
}
</Script>
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> Untitled Page </title>
</Head>
<Body>
<Form id = "form1" runat = "server">
<Div>
<Asp: ListBox ID = "ListBox1" runat = "server"/>
<Asp: Button ID = "Button1" runat = "server" Text = "Button" OnClick = "button#click"/> </div>
</Form>
</Body>
</Html>