一、先在前台页面中拖入一个listbox控件和四个button控件,可以对它们的样式进行一下修改。
<style type="text/css">
.left {
float:left;
width:120px;
}
.right {
float:right;
width:80px;
}
.all {
width:200px;
}
</style>
二,在后台相对应的button按钮的click方法中加入代码。
protected void Button1_Click(object sender, EventArgs e)
{
//ListBox1.Items.Remove(ListBox1.SelectedItem);
//上移
if (ListBox1.SelectedIndex > 0) {
int idx = ListBox1.SelectedIndex;
ListBox1.Items.Insert(ListBox1.SelectedIndex - 1, ListBox1.SelectedItem.ToString());
ListBox1.Items.RemoveAt(ListBox1.SelectedIndex);
ListBox1.SelectedIndex = idx - 1;
}
}
protected void Button2_Click(object sender, EventArgs e)
{
//下移
if (ListBox1.SelectedIndex < ListBox1.Items.Count - 1)
{
ListBox1.Items.Insert(ListBox1.SelectedIndex, ListBox1.Items[ListBox1.SelectedIndex + 1].ToString());
ListBox1.Items.RemoveAt(ListBox1.SelectedIndex + 1);
}
}
protected void Button3_Click(object sender, EventArgs e)
{
//循环上移
if (ListBox1.SelectedIndex == 0) {
ListBox1.Items.Insert(ListBox1.Items.Count,ListBox1.SelectedItem.ToString());
ListBox1.Items.RemoveAt(ListBox1.SelectedIndex);
}
}
protected void Button4_Click(object sender, EventArgs e)
{
//循环下移
if (ListBox1.SelectedIndex == ListBox1.Items.Count-1) {
ListBox1.Items.Insert(0, ListBox1.SelectedItem.ToString());
ListBox1.Items.RemoveAt(ListBox1.SelectedIndex);
}
}