zoukankan      html  css  js  c++  java
  • listbox 上下移动 (asp.net C#)

     protected void btnup_Click(object sender, EventArgs e)
        {

            if (lb_busspot.SelectedIndex == -1)
            {
                return;
            }

            //获得连续选中的项索引
            int[] Indices = lb_busspot.GetSelectedIndices();
            int length = Indices.Length;
            string text;
            string value;
            //如果选择的最小索引是0,表示是最上面的项
            if (Indices[0] == 0)
            {
                return;
            }

            //判断选择多项时是否是连续的项
            if (Indices.Length != 1 && Indices[0] + length - 1 != Indices[length - 1])
            {

                MessageBox.Show("Page", "请选择连续的项!");
                return;       
            }
            //将选中的上面一项未选中的值赋予临时变量
            text = lb_busspot.Items[Indices[0] - 1].Text;
            value = lb_busspot.Items[Indices[0] - 1].Value;

            for (int i = 0; i < length; i++)
            {
                lb_busspot.Items[Indices[i] - 1].Text = lb_busspot.Items[Indices[i]].Text;
                lb_busspot.Items[Indices[i] - 1].Value = lb_busspot.Items[Indices[i]].Value;
                //保证被选中状态
                lb_busspot.Items[Indices[i] - 1].Selected = true;
                lb_busspot.Items[Indices[i]].Selected = false;
            }
            //将选中的上面第一条未选中的值赋予到下面
            lb_busspot.Items[Indices[0] + length - 1].Text = text;
            lb_busspot.Items[Indices[0] + length - 1].Value = value;
        }

        protected void btndown_Click(object sender, EventArgs e)
        {
            if (lb_busspot.SelectedIndex==-1)
            {
                return;
            }
            //获得连续选中的项索引
            int[] Indices = lb_busspot.GetSelectedIndices();
            int length = Indices.Length;

            string text;
            string value;
            //如果选择的是最底下的项

            if (Indices[length-1]==lb_busspot.Items.Count-1)
            {
                return;
            }

            //判断选择多项时是否是连续的项

            if (Indices.Length !=1&&Indices[0]+length -1!=Indices[length -1])
            {
                MessageBox.Show("Page", "请选择连续的项!");
                return;
            }
            //将选中的下面一项未选中的值赋予临时变量
            text = lb_busspot.Items[Indices[length - 1] + 1].Text;
            value = lb_busspot.Items[Indices[length - 1] + 1].Value;
            for (int i = length; i > 0; i--)
            {
                lb_busspot.Items[Indices[i - 1] + 1].Text = lb_busspot.Items[Indices[i - 1]].Text;
                lb_busspot.Items[Indices[i - 1] + 1].Value = lb_busspot.Items[Indices[i - 1]].Value;
                lb_busspot.Items[Indices[i - 1] + 1].Selected = true;
                lb_busspot.Items[Indices[i - 1]].Selected = false;
            }
            //将下面第一条未选中的项的值赋予到上
            lb_busspot.Items[Indices[0]].Text = text;
            lb_busspot.Items[Indices[0]].Value = value;

        }

  • 相关阅读:
    PHP发送邮件标题乱码的解决
    PHP方法之 mb_substr
    HTML 文件类表单元素如何限制上传类型,Accept属性设置
    Jquery 自定义动画同步进行如何实现?
    王小胖之 Base64编码/解码
    王小胖之 URL编码和解码
    王小胖之中文汉字转拼音
    跟左神学算法7 进阶数据结构(哈希相关)
    操作系统复习笔记1
    计算机网络复习笔记2
  • 原文地址:https://www.cnblogs.com/top5/p/1633541.html
Copyright © 2011-2022 走看看