ASP.NET List Box

放肆的年华 提交于 2019-12-12 23:02:00

问题


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??


回答1:


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

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"

or

         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);    
        }
     }

with

SelectionMode="Single"

hope it helps



来源:https://stackoverflow.com/questions/7721901/asp-net-list-box

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!