惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Stack Overflow Blog
Stack Overflow Blog
云风的 BLOG
云风的 BLOG
G
Google Developers Blog
J
Java Code Geeks
C
Check Point Blog
Last Week in AI
Last Week in AI
Microsoft Azure Blog
Microsoft Azure Blog
Blog — PlanetScale
Blog — PlanetScale
月光博客
月光博客
Vercel News
Vercel News
The GitHub Blog
The GitHub Blog
L
LangChain Blog
有赞技术团队
有赞技术团队
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园 - 司徒正美
IT之家
IT之家
Martin Fowler
Martin Fowler
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
T
Tailwind CSS Blog
U
Unit 42
Jina AI
Jina AI
Microsoft Security Blog
Microsoft Security Blog
I
InfoQ

博客园 - 阿社

!!如何看到真实的服务器 错误提示 !访问网站出现Directory Listing Denied 是什么原因? !后台登录总 提示验证码错误!! !设置IIS后 访问提示 页面不存在 HTTP 500错误 Windows2003网络服务器安全攻略! Win2003 ISS下Asp配置技巧 http 500内部服务器错误 !商城登录后不能自动在社区登录! ASP.NET中TreeView控件使用小结 使用IE WebControls中的TabStrip控件和MultiPage控件实现选项卡式风格页面 [程序员必看]请不要做浮躁的人 未能在设计视图中打开,在中以不同方式将值括起来 我应该用DataReader类还是DataSet类呢?” DataGrid、DataList和Repeater控件 DropDownList控件使用 C#笔记 C#常用函数和方法集汇总-日期函数 ASP常用三十三种代码 ASP.net数据绑定概述和语法 编程控制控件Style属性
ListBox控件使用
阿社 · 2006-09-04 · via 博客园 - 阿社

ListBox 可以通过ListSelectionMode 设置多选,默认值为 Single,
<%@ Page Language="C#" AutoEventWireup="True" %>
<html>
 <head>
 
     <script runat="server">
 
         void AddBtn_Click(Object Sender, EventArgs e)
         {
             if (ListBox1.SelectedIndex > -1) //检查是否有选中项,否则会报错!未将引用指向对象实列
             {
                  if (ListBox2.Items.FindByValue(ListBox1.SelectedItem.Text) == null) //如果2中未存在选中的值
                 {
                      ListItem Item = new ListItem();
                      // Text and Value are swapped.
                     Item.Text = ListBox1.SelectedItem.Value;
                     Item.Value = ListBox1.SelectedItem.Text;
                     ListBox2.Items.Add(Item);
                  }
             }
         }
 
         void DelBtn_Click(Object Sender, EventArgs e)
         {
             if (ListBox2.SelectedIndex > -1) //检查是否有选中项,否则会报错!未将引用指向对象实列

             {
                 ListBox2.Items.Remove(ListBox2.SelectedItem);
             }
         }
 
     </script>
 
 </head>
 <body>
 
     <h3>ListItem Example</h3>
     <p>
     <form runat=server>
     <table>
     <tr><td>
         <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:ListBox>
     </td><td>
         <asp:button Text="--->" OnClick="AddBtn_Click" runat="server" /><br>
         <asp:button Text="<---" OnClick="DelBtn_Click" runat="server" />
    </td><td>
         <asp:ListBox id=ListBox2 Width="100px" runat="server"/>
     </td></tr>
     </table>
     </form>
 
 </body>
 </html>

posted on 2006-09-04 18:05  阿社  阅读(477)  评论()    收藏  举报