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:效果图

  • 相关阅读:
    resin
    tomcat
    vba打开输入文件
    获取文件夹下所有文件2
    获取文件夹下所有文件
    修改Execl中sheet名的指定字符串为指定字符串
    SpringMVC入门到精通(一)
    Java JDBC
    Java反射
    Java日期格式化
  • 原文地址:https://www.cnblogs.com/thbbsky/p/3092842.html
Copyright © 2011-2022 走看看