扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
<% @ Page Language = "C#" %> <html > <head > <script runat = "server" > protected void Button_Click ( object sender , EventArgs e ) { //按钮"增加条目"事件处理程序 if ( sender == Add ) { if ( txtItem.Text != "" ) { lstItem . Items . Add ( new ListItem ( txtItem . Text ) ) ; } } //按钮"删除"事件处理程序 if ( sender == Del ) { if ( lstItem . SelectedIndex > -1 ) { lstItem . Items . Remove ( lstItem . SelectedItem ) ; } } //按钮"向上移位"和"向下移位"事件处理程序 if ( ( sender == Up && lstItem . SelectedIndex > 0 ) || ( sender == Down && lstItem . SelectedIndex < lstItem . Items . Count - 1 ) ) { int offset ; if ( sender == Up ) { offset = -1 ; } else { offset = 1 ; } ListItem lstTemp = new ListItem ( lstItem . SelectedItem . Text , lstItem . SelectedItem . Value ) ; lstItem . Items [ lstItem.SelectedIndex ] .Text = lstItem . Items [ lstItem . SelectedIndex + offset ] . Text ; lstItem . Items [ lstItem . SelectedIndex ] . Value = lstItem . Items [ lstItem . SelectedIndex + offset ] . Value ; lstItem . Items [ lstItem . SelectedIndex + offset ] . Text = lstTemp . Text ; lstItem . Items [ lstItem . SelectedIndex + offset ] . Value = lstTemp . Value ; lstItem . SelectedIndex = lstItem . SelectedIndex + offset ; } //按钮"至首条"事件处理程序 if ( sender == First ) { if ( lstItem . Items . Count > 0 ) { lstItem . SelectedIndex = 0 ; } } //按钮"至尾条"事件处理程序 if ( sender == Last ) { if ( lstItem . Items . Count > 0 ) { lstItem . SelectedIndex = lstItem . Items . Count - 1 ; } } //按钮"上一条"事件处理程序 if ( sender == Prev ) { if ( lstItem . SelectedIndex > 0 ) { lstItem . SelectedIndex = lstItem . SelectedIndex - 1 ; } } //按钮"下一条"事件处理程序 if ( sender == Next ) { if ( lstItem . SelectedIndex < lstItem . Items . Count - 1 ) { lstItem . SelectedIndex = lstItem . SelectedIndex + 1 ; } } } </script > </head > <body > <form runat = "server" > <table > <tr > <td Colspan = 2 > <h1 > <font color = "red" > WinForm组件ListBox演示程序 </font > </h1 > </td> </tr > <tr > <td > 请输入要增加的条目名称:</td > <td > <asp:TextBox id = "txtItem" TextMode = "SingleLine" runat = "server"/> <asp:Button id = Add Text = "增加条目" runat = "server" onclick = "Button_Click"/> </td > </tr > <tr > <td >ListBox: <br > <asp:ListBox id = "lstItem" Width = 200 Height = 250 runat = "server" > <asp:ListItem > 第一个条目 </asp:ListItem > </asp:ListBox > </td > <td > <asp:Button id = "Del" Text = "删除" runat = "server" onclick = "Button_Click" /> <asp:Button id = "Up" Text = "向上移位" runat = "server" onclick = "Button_Click" /> <asp:Button id = "Down" Text = "向下移位" runat = "server" onclick = "Button_Click" /> <asp:Button id = "First" Text = "至首条" runat = "server" onclick = "Button_Click" /> <asp:Button id="Prev" Text = "上一条" runat = "server" onclick = "Button_Click" /> <asp:Button id = "Next" Text = "下一条" runat = "server" onclick = "Button_Click" /> <asp:Button id = "Last" Text = "至尾条" runat = "server" onclick = "Button_Click" /> </td > </tr > </table > </form > <body > </html > |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者