实现ListBox1的Item项上移与下移!!!

 private void Page_Load(object sender, System.EventArgs e)
  {
   // 在此处放置用户代码以初始化页面

   if(!Page.IsPostBack)
   {
    ArrayList al = new ArrayList();
    al.Add("1");
    al.Add("2");
    al.Add("3");
    al.Add("4");
    al.Add("5");
    al.Add("6");
    ListBox1.DataSource = al;
    ListBox1.DataBind();
   }

//向下
 private void Button2_Click(object sender, System.EventArgs e)
  {
   if(ListBox1.SelectedIndex<ListBox1.Items.Count-1)
   {
    //交换位置
    string strTempUp = ListBox1.Items[ListBox1.SelectedIndex].Text;
    ListBox1.Items[ListBox1.SelectedIndex].Text = ListBox1.Items[ListBox1.SelectedIndex+1].Text;
    ListBox1.Items[ListBox1.SelectedIndex+1].Text = strTempUp;

 //选中下一个Item项
    ListBox1.SelectedIndex = ListBox1.SelectedIndex+1;
    ListBox1.Items[ListBox1.SelectedIndex].Selected = true;
   }  
  }

//向上
  private void Button1_Click(object sender, System.EventArgs e)
  {
   if(ListBox1.SelectedIndex>0)
   {
   //交换位置
    string strTempUp = ListBox1.Items[ListBox1.SelectedIndex].Text;
    ListBox1.Items[ListBox1.SelectedIndex].Text = ListBox1.Items[ListBox1.SelectedIndex-1].Text;
    ListBox1.Items[ListBox1.SelectedIndex-1].Text = strTempUp;

    //选中上一个Item项       
    ListBox1.SelectedIndex = ListBox1.SelectedIndex - 1;
    ListBox1.Items[ListBox1.SelectedIndex].Selected=true;
  }

posted on 2004-08-16 15:21 阿森 阅读(463) 评论(1)  编辑 收藏

评论

#1楼  回复 引用   

这个偶有点看不懂诶`
咋办
咋办`
呜呜~~
2007-11-26 09:33 | 恋[未注册用户]

导航

<2012年2月>
2930311234
567891011
12131415161718
19202122232425
26272829123
45678910

公告

昵称:阿森
园龄:7年6个月
粉丝:0
关注:0

搜索

 
 

常用链接

随笔档案

最新评论