列表框多个选定项 [英] Listbox multiple selected items

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

问题描述

我正在使用选择模式为多个的列表框.

I am using Listbox with selection mode as multiple.

<asp:ListBox ID="ListBox1" SelectionMode="Multiple"  runat="server">
        <asp:ListItem>one</asp:ListItem>
        <asp:ListItem>two</asp:ListItem>
        <asp:ListItem>thr</asp:ListItem>
        </asp:ListBox>



下面的代码在列表框中显示选定的项目.但是,如何在列表框中显示多个选定的项目.



The following code displays the selected item in Listbox. But how do i display multiple selected items in the listbox.

protected void Button1_Click(object sender, EventArgs e)
    {
// let the array srr be the selected items
        string[] srr = { "one", "thr" };
        foreach (string item in srr)
        {
            ListBox1.SelectedValue = item;
        }
    }


谢谢.

推荐答案

protected void Button1_Click(object sender, EventArgs e)
{
 string[] srr = { "one", "thr" };
 foreach (string item in srr)
 {
 for (int intItem = 0; intItem &lt;= ListBox1.Items.Count - 1; intItem++) {
      if(ListBox1.Items(intItem).Text == item){
            ListBox1.Items(intItem).Selected = true;
      }
    }
}


检查每个项目的选定属性.看一下此链接上的示例:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listcontrol.items.aspx [
Check the selected property of each item. Have a look at the example at this link:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listcontrol.items.aspx[^]

Good luck!


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

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