zoukankan      html  css  js  c++  java
  • asp.net ListBox单选、全选、清除等功能

    1:注意要得把两个listbox的selectectionmode属性设置为mutiple

    2 后台代码:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    public partial class TestListBox : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
               
                ListBox2Bind();
              
            }
        }
    
        private void ListBox2Bind()
        {
            string[] str = new string[] { "北京","上海","福建","广东","浙江" };
            for (int i = 0; i < str.Length - 1; i++)
            {
                ListBox2.Items.Add(str[i]);
            }
    
        }
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            
            int count = ListBox2.Items.Count;
            int index = 0;
            for (int i = 0; i < count; i++)
            {
                ListItem item = ListBox2.Items[index];
                if (ListBox2.Items[index].Selected == true)
                {
                    ListBox2.Items.Remove(item);
                    ListBox3.Items.Add(item);
                    index--;
                }
                index++;
            }
        }
        protected void btnDel_Click(object sender, EventArgs e)
        {
            int count = ListBox3.Items.Count;
            int index = 0;
            for (int i = 0; i < count; i++)
            {
                ListItem item = ListBox3.Items[index];
                if (ListBox3.Items[index].Selected == true)
                {
                    ListBox3.Items.Remove(item);
                    ListBox2.Items.Add(item);
                    index--;
                }
                index++;
            }
    
        }
        protected void AddAll_Click(object sender, EventArgs e)
        {
            int count = ListBox2.Items.Count;
            int index = 0;
            for (int i = 0; i < count; i++)
            {
                ListItem item = ListBox2.Items[index];
                ListBox2.Items.Remove(item);
                ListBox3.Items.Add(item);
            }
            index++;
        }
        protected void DelAll_Click(object sender, EventArgs e)
        {
            int count = ListBox3.Items.Count;
            int index = 0;
            for (int i = 0; i < count; i++)
            {
                ListItem item = ListBox3.Items[index];
                ListBox3.Items.Remove(item);
                ListBox2.Items.Add(item);
            }
            index++;
        }
    }
    

     3:效果图

  • 相关阅读:
    没有精神分裂的测试不是一个好家长
    防火墙中配置开放 8080端口--续上一篇
    rocketMQ(一)基础环境
    如何做一个对账系统
    通用对账系统介绍与设计(上)
    pdf转图片
    虚拟机加载类机制
    jenkins
    zookeeper和dubbo
    正则日常积累
  • 原文地址:https://www.cnblogs.com/thbbsky/p/3092842.html
Copyright © 2011-2022 走看看