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);
                    }
                }
            }
        }

posted on 2012-04-18 15:34  MyBeN  阅读(414)  评论(0编辑  收藏  举报

导航