Chinaunix首页 | 论坛 | 博客
  • 博客访问: 55327
  • 博文数量: 16
  • 博客积分: 125
  • 博客等级: 民兵
  • 技术积分: 205
  • 用 户 组: 普通用户
  • 注册时间: 2012-12-04 13:05
文章分类

全部博文(16)

文章存档

2016年(2)

2015年(3)

2013年(6)

2012年(5)

我的朋友

分类: C#/.net

2013-08-14 14:13:57

做一个小例子,实现两个listbox的数据实现“左移”,“右移”、“清除”某一listbox的数据的功能。
前台两个listbox的控件代码如下:
      

            ListBox1

       

       

       

            ListBox2

       

           
           

       

       

                            Style="background: url(../images/s_bgs.png) repeat-x 0 -118px; width: 100px;
                border-color: #7F9DB9 #7F9DB9 #7F9DB9; border-right: 1px solid #7F9DB9; border-style: solid;
                border-width: 1px; box-shadow: 0 1px 1px #FFFFFF; display: block; float: left;
                vertical-align: top; position: relative; top: 110px; left: 15px; padding: 0;
                margin: 0;" />
           
           
       

       

           
       



后台cs方法如下:

//清楚全部
    protected void btnClear_Click(object sender, EventArgs e)
    {
        int count = listSend.Items.Count;
        int index = 0;

        for (int i = 0; i < count; i++)
        {
            ListItem item = listSend.Items[index];
            listSend.Items.Remove(item);
        }
        index++;
    }
    //右移
    protected void btnAddRight_Click(object sender, EventArgs e)
    {
        if (listYuan.SelectedIndex <= -1)
        {
            Common.ShowAlter(this.Page, "提示", "请选择要要右移的数据");
            return;
        }

        int count = listYuan.Items.Count;
        int index = 0;
        for (int i = 0; i < count; i++)
        {
            ListItem item = listYuan.Items[index];
            if (item.Selected == true)
            {

                listYuan.Items.Remove(item);
                listSend.Items.Add(item);
                this.listSend.SelectedIndex = (listSend.Items.Count - 1);
                index--;
            }
            index++;
        }

    }
    //左移
    protected void btnAddLeft_Click(object sender, EventArgs e)
    {
        int count = listSend.Items.Count;
        int index = 0;
        for (int i = 0; i < count; i++)
        {
            ListItem item = listSend.Items[index];
            if (item.Selected == true)
            {

                listSend.Items.Remove(item);
                listYuan.Items.Add(item);
                this.listYuan.SelectedIndex = (this.listYuan.Items.Count - 1);
                index--;
            }
            index++;
        }
    }

阅读(1462) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~