ASP.NET 2.0中隐藏listbox的某一项
2024-07-10 12:56:44
供稿:网友
在asp.net 2.0中,可以隐藏listbox中的某一项,比如
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>