[英]Cannot select multiple items in Listbox
I have a ListBox
and DropDownList
in GridView
EditItemTemplate
. 我在GridView
EditItemTemplate
有一个ListBox
和DropDownList
。 On rowEditing
, I want to select all the items in ListBox
. 在rowEditing
,我想选择ListBox
所有项目。 Below is my code: 下面是我的代码:
string categories = (e.Row.FindControl("lblCategoryID") as Label).Text;
ListBox lbx = (ListBox)e.Row.FindControl("lbSelectedCategory");
DropDownList drp = (DropDownList)e.Row.FindControl("drpCat");
List<string> TagIds = categories.Split(',').ToList();
lbx.SelectionMode = ListSelectionMode.Multiple;
foreach (string s in TagIds)
{
ListItem li = drp.Items.FindByValue(s);
lbx.Items.Add(li);
}
Here the items gets added into the Listbox
. 此处,项目将添加到Listbox
。
But when I try to select the multiple items, 但是当我尝试选择多个项目时,
for (int i = 0; i < lbx.Items.Count; i++)
{
lbx.Items[i].Selected = true;
}
I get error : 我收到错误消息:
cannot select multiple items in a dropdownlist. 无法在下拉列表中选择多个项目。
Aspx: Aspx:
<EditItemTemplate>
<asp:Label ID="lblCategoryID" Text='<%# Bind("tag_id") %>' runat="server"></asp:Label>
<asp:ListBox ID="lbSelectedCategory" Visible="false" Width="150px" runat="server"
SelectionMode="Multiple" CssClass="chosen-select"></asp:ListBox>
<asp:DropDownList ID="drpCat" AutoPostBack="true"
OnSelectedIndexChanged="drpCat_SelectedIndexChanged" CssClass="chosen-select" runat="server">
</asp:DropDownList>
</EditItemTemplate>
Can anyone help me solving this Issue? 谁能帮我解决这个问题?
与其在下拉列表中查找行并将相同的行添加到ListBox中,不如尝试从下拉列表中创建一个与ListItem具有相同值的新ListItem并添加它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.