asp.net Listbox实现双向加入、删除

 

/// <summary>
        /// 添加服务器名称(可多选)
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void BT_Add_Click(object sender, EventArgs e)
        {
            int selectNum = this.LST_Left.Items.Count;
            if (selectNum > 0)
            {
                for (int i = selectNum-1; i >= 0; i--)
                {
                    if (this.LST_Left.Items[i].Selected)
                    {
                        ListItem tmpListItem = this.LST_Left.Items[i];
                        this.LST_Right.Items.Add(tmpListItem);
                        this.LST_Left.Items.Remove(tmpListItem);
                    }
                }
            }
           
        }

        /// <summary>
        /// 删除服务器名称(可多选)
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void BT_DEL_Click(object sender, EventArgs e)
        {
            int selectNum = this.LST_Right.Items.Count;
            if (selectNum > 0)
            {
                for (int i = selectNum - 1; i >= 0; i--)
                {
                    if (this.LST_Right.Items[i].Selected)
                    {
                        ListItem tmpListItem = this.LST_Right.Items[i];
                        this.LST_Left.Items.Add(tmpListItem);
                        this.LST_Right.Items.Remove(tmpListItem);
                    }
                }
            }
        }

转载于:https://www.cnblogs.com/MyBeN/archive/2012/04/18/2455382.html

相关文章:

  • 2021-11-30
  • 2021-06-05
  • 2021-06-27
  • 2021-12-11
  • 2022-03-07
  • 2021-09-23
猜你喜欢
  • 2021-06-08
  • 2021-10-04
  • 2021-04-26
  • 2021-05-25
  • 2022-02-04
  • 2021-04-23
相关资源
相似解决方案