ASP.NET列表框 [英] ASP.NET List Box

查看:107
本文介绍了ASP.NET列表框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立一个网站,其中一个页面具有其中设置的名称将是displayed.There是另一个旁边的框这个box.User应该能够从第一清单中选择几个名字列表框,打一个箭头按钮,做的所有第一框选定的名称会出现在第二个盒子。
任何人都可以请帮我对如何做到这一点?

I am creating a web site in which one page has a list box in which set of names will be displayed.There s another box next to this box.User should be able to select few names from the first list,hit a arrow button,doing which all the selected names of first box will appear on the second box. Can anyone please help me out as to how to do this??

推荐答案

假设的ID的>>按钮btnLoad其Click事件处理程序是btnLoad_Click

Suppose that id of the ">>" button is btnLoad and its click event handler is btnLoad_Click

LST1是第一个列表框和LST2是第二个列表框:

lst1 is First List box and lst2 is Second list box:

    protected void btnLoad_Click(object sender, EventArgs e)
    {
        lst1.GetSelectedIndices();
        foreach (int item in lst1.GetSelectedIndices())
        {
            lst2.Items.Add(lst1.Items[item]);    
        }
    }

请确保两个列表框应该有

be sure that both list boxes should have

SelectionMode="Multiple"

         protected void btnLoad_Click(object sender, EventArgs e)
     {
        lst1.GetSelectedIndices();
        foreach (int item in lst1.GetSelectedIndices())
        {
            var tempItem = lst1.Items[item];
            tempItem.Selected = false;
            lst2.Items.Add(tempItem);    
        }
     }

SelectionMode="Single"

希望它能帮助

这篇关于ASP.NET列表框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆