Saturday, October 30, 2010

Moving items from one list box to another

 Output




 protected void Button1_Click(object sender, EventArgs e)

   {
int index=0;
        index = ListAvCh.SelectedIndex;
      if(ListAvCh.Items.Count > 0)
      {
          if(ListAvCh.SelectedIndex>-1)
          {
              string _value = ListAvCh.SelectedItem.Value;
              string _text = ListAvCh.SelectedItem.Text;
              ListItem item = new ListItem();
              item.Text = _text;
              item.Value = _value;
              ListSeCh.Items.Add(item);
              ListAvCh.Items.Remove(item);
           try
              {
                  if (ListAvCh.Items.Count == index)
                  {
                      ListAvCh.Items[index - 1].Selected = true;
                  }
                  else if (ListAvCh.Items.Count > index)
                  {
                      ListAvCh.Items[index].Selected = true;
                  }
              }
              catch(Exception )
              {

              }
          }
      }
      for (int a = 0; a < ListSeCh.Items.Count; a++)
      {
          ListSeCh.Items[a].Selected = true;
      }

    }
    protected void BtnGroupRightSelect_Click(object sender, EventArgs e)
    {
        int _count = ListAvCh.Items.Count;
        if (_count != 0)
        {
            for (int i = 0; i < _count; i++)
            {
                ListItem item = new ListItem();
                item.Text = ListAvCh.Items[i].Text;
                item.Value = ListAvCh.Items[i].Value;
                ListSeCh.Items.Add(item);
            }

            for (int a = 0; a < ListAvCh.Items.Count; a++)
            {
                ListSeCh.Items[a].Selected = true;
            }
        }
        ListAvCh.Items.Clear(); 

    }
    protected void BtnleftSingleSelect_Click(object sender, EventArgs e)
    {
        int index = 0;
        index = ListSeCh.SelectedIndex;
        if (ListSeCh.Items.Count > 0)
        {
            if (ListSeCh.SelectedIndex > -1)
            {
                string _value = ListSeCh.SelectedItem.Value;
                string _text = ListSeCh.SelectedItem.Text;
                ListItem item = new ListItem();
                item.Text = _text;
                item.Value = _value;
                ListAvCh.Items.Add(item);
                ListSeCh.Items.Remove(item);
                try
                {
                    if (ListSeCh.Items.Count == index)
                    {
                        ListSeCh.Items[index - 1].Selected = true;
                    }
                    else if (ListSeCh.Items.Count > index)
                    {
                        ListSeCh.Items[index].Selected = true;
                    }
                }
                catch (Exception)
                {

                }
            }
        }
    }
    protected void BtnleftMulSel_Click(object sender, EventArgs e)
    {
        int _count = ListSeCh.Items.Count;
        if (_count != 0)
        {
            for (int i = 0; i < _count; i++)
            {
                ListItem item = new ListItem();
                item.Text = ListSeCh.Items[i].Text;
                item.Value = ListSeCh.Items[i].Value;
                ListAvCh.Items.Add(item);
            }
        }
        ListSeCh.Items.Clear();
    }
   

No comments:

Post a Comment