- protected void Page_Load(object sender, EventArgs e)
- {
- if (!Page.IsPostBack)
- {
- for (int i = 0; i < 10; i++)
- {
- this.lbxSource.Items.Add(new ListItem("★"+i, i.ToString()));
- }
- }
- }
- protected void listBoxOperate_OnCommand(object sender,CommandEventArgs e)
- {
- ArrayList arrTo = new ArrayList();
- switch (e.CommandName)
- {
- case "ToRight":
- if (this.lbxSource.SelectedIndex == -1)
- {
- break;
- }
- else
- {
- foreach(ListItem item in lbxSource.Items)
- {
- if(item.Selected)
- {
- arrTo.Add(item);
- }
- }
- foreach (ListItem item in arrTo)
- {
- this.lbxTo.Items.Add(item);
- this.lbxSource.Items.Remove(item);
- }
- break;
- }
- case "AllToRight":
- if (this.lbxSource.Items.Count > 0)
- {
- foreach (ListItem item in lbxSource.Items)
- {
- this.lbxTo.Items.Add(item);
- }
- this.lbxSource.Items.Clear();
- break;
- }
- else
- {
- break;
- }
- case "ToLeft":
- if(this.lbxTo.SelectedIndex == -1)
- {
- break;
- }
- else
- {
- foreach (ListItem item in lbxTo.Items)
- {
- if (item.Selected)
- {
- arrTo.Add(item);
- }
- }
- foreach (ListItem item in arrTo)
- {
- this.lbxSource.Items.Add(item);
- this.lbxTo.Items.Remove(item);
- }
- break;
- }
- break;
- case "AllToLeft":
- if (this.lbxTo.Items.Count > 0)
- {
- foreach (ListItem item in lbxTo.Items)
- {
- this.lbxSource.Items.Add(item);
- }
- this.lbxTo.Items.Clear();
- break;
- }
- else
- {
- break;
- }
- case "ToUp":
- for (int i = 0; i < lbxTo.Items.Count; i++)
- {
- if (lbxTo.Items[i].Selected)
- {
- if (i > 0 && lbxTo.SelectedIndex > -1)
- {
- ListItem item = lbxTo.Items[i];
- lbxTo.Items.RemoveAt(i);
- lbxTo.Items.Insert(i - 1, item);
- }
- }
- }
- break;
- case "ToDown":
- for (int i = lbxTo.Items.Count - 1; i > -1; i--)
- {
- if (lbxTo.Items[i].Selected)
- {
- ListItem item = lbxTo.Items[i];
- if (i < lbxTo.Items.Count - 1)
- {
- lbxTo.Items.Insert(i + 2, item);
- lbxTo.Items.RemoveAt(i);
- }
- }
- }
- break;
- }
- }
listbox
最新推荐文章于 2024-04-28 14:05:57 发布