Thursday, July 24, 2014

ListBox Multi Select Option to Move Item in asp.net

Move Item from Left to Right List Box and Vice-Versa.



Code Snippet : 

    protected void btnRight_Click(object s, EventArgs e)
        {
            int[] indexes = this.lstLeftList.GetSelectedIndices();
            ListItem[] items = new ListItem[indexes.Length];
            for (int i = 0; i < indexes.Length; i++)
            {
                items[i] = this.lstLeftList.Items[indexes[i]];
            }

            for (int i = 0; i < items.Length; i++)
            {
                this.lstRightList.Items.Add(items[i]);
                this.lstLeftList.Items.Remove(items[i]);
            }
        }

        protected void btnLeft_Click(object s, EventArgs e)
        {
            int[] indexes = this.lstRightList.GetSelectedIndices();
            ListItem[] items = new ListItem[indexes.Length];
            for (int i = 0; i < indexes.Length; i++)
            {
                items[i] = this.lstRightList.Items[indexes[i]];
            }

            for (int i = 0; i < items.Length; i++)
            {
                this.lstLeftList.Items.Add(items[i]);
                this.lstRightList.Items.Remove(items[i]);
            }
        }

No comments:

Post a Comment