列表框多选问题

时间:2010-06-08 07:41:00

标签: c# asp.net

Hello Friends我在aspx页面中使用了一个列表框控件 我已将多个选择属性设置为true,但是当我尝试选择多个项目时 它没有选择多个项目,它只选择一个我必须以编程方式做一些事情这里是我的代码

<html>

 <form id="form1" runat="server">
     <div>
         <asp:ListBox ID="ListBox1" runat="server"
 SelectionMode="Multiple">
         <asp:ListItem Text="hi" Value="hi"></asp:ListItem>
         <asp:ListItem Text="hi" Value="hi"></asp:ListItem>
         <asp:ListItem Text="hi" Value="hi"></asp:ListItem>
         <asp:ListItem Text="hi" Value="hi"></asp:ListItem>
         </asp:ListBox>
     </div>
     </form>
</html>

代码背后没有任何东西......我想知道它为什么不选择多个项目的..  我使用System.Web.UI.WebControls使用命名空间;同样但无济于事..

2 个答案:

答案 0 :(得分:0)

以下是包含使用示例的文档链接:

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listbox.aspx

要在下拉列表中选择多个项目,请确保使用ctrl键并单击所需的项目。您可能需要更改下拉列表的大小(以便一次显示多个项目)才能更轻松地查看。

我从链接上的第二个示例开始,因为这是您尝试做的一个示例(使用明智)。

答案 1 :(得分:0)

您必须使用ListBox的“FindByValue”方法

foreach (string selectedValue in SelectedValuesArray)
                    {
                        lstBranch.Items.FindByValue(selectedValue).Selected = true;
                    }
相关问题