在asp.net 2.0中,可以隐藏listbox中的某一项,比如
ListItem item = new ListItem(text, value, enabled);
当然,也可以用
ListItem item = new ListItem(text, value, enabled);
当然,也可以用
item.Enabled = false;
虽然在页面中隐藏了,但依然可以用代码来访问隐藏的选项的,下面是一个例子
<%
@ 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 Button1_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 ="Button1_Click" /></ div >
</ form >
</ body >
</ html >
< 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 Button1_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 ="Button1_Click" /></ div >
</ form >
</ body >
</ html >
本文转自高海东博客园博客,原文链接:http://www.cnblogs.com/ghd258/archive/2005/10/27/262995.html,如需转载请自行联系原作者