ListBox 上,下排序

向下

protected void Button2_Click(object sender, EventArgs e)
    {
        int i = this.ListBox1.SelectedIndex;
        if ((i - 1) > -1 && i != -1)
        {
            ListItem li = this.ListBox1.SelectedItem;
            this.ListBox1.Items.Remove(li);
            this.ListBox1.Items.Insert(i - 1, li);
        }

    }

 

向上

protected void Button3_Click(object sender, EventArgs e)
    {
        int i = this.ListBox1.SelectedIndex;
        if (i != this.ListBox1.Items.Count - 1)
        {
            ListItem li = this.ListBox1.SelectedItem;
            this.ListBox1.Items.Remove(li);
            this.ListBox1.Items.Insert(i + 1, li);
        }
        else { }
    }

你可能感兴趣的:(Asp.Net,[C#])