chuang4630
asked on
How do you remove the item from the list box control?
I'd like to move the selected item (single selection list box) from lstAvailableTemplates to lstAssignedTemplates.
When the user press the button "Add", the item is supposed to move from one list to another. However, I can see the new item being added to the destination, but NOT being removed from the lst lstAvailableTemplates (list box control).
Anyone knows why?
protected void btnAdd_Click(object sender, EventArgs e)
{
string item = lstAvailableTemplates.Sele ctedItem.T oString();
lstAssignedTemplates.Items .Add(item) ;
lstAvailableTemplates.Item s.Remove(i tem);
}
When the user press the button "Add", the item is supposed to move from one list to another. However, I can see the new item being added to the destination, but NOT being removed from the lst lstAvailableTemplates (list box control).
Anyone knows why?
protected void btnAdd_Click(object sender, EventArgs e)
{
string item = lstAvailableTemplates.Sele
lstAssignedTemplates.Items
lstAvailableTemplates.Item
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
It works, Thanks. But there is anothere probelm.
Select one item/press button, it works. When I select the second item/press button, it fails: System.Web.HttpException: Cannot have multiple items selected when the SelectionMode is Single.
How do I fix that while keeping the single selection mode?
Select one item/press button, it works. When I select the second item/press button, it fails: System.Web.HttpException: Cannot have multiple items selected when the SelectionMode is Single.
How do I fix that while keeping the single selection mode?
Hi,
User ClearSelection to clear the selection before select the section item.
For Example,
ListBox2.ClearSelection()
Thanks
User ClearSelection to clear the selection before select the section item.
For Example,
ListBox2.ClearSelection()
Thanks
ASKER
mrrajpatel:
Thanks. Could you please post your answer to the following link so I can give you the points? Thanks again.
https://www.experts-exchange.com/questions/21868037/How-to-select-remove-the-item-from-list-box-single-selection-mode.html
<asp:ListBox ID="ListBox1" runat="server">
<asp:ListItem Text=1 Value=1></asp:ListItem>
<asp:ListItem Text=1 Value=1></asp:ListItem>
<asp:ListItem Text=1 Value=1></asp:ListItem>
</asp:ListBox>
<asp:ListBox ID="ListBox2" runat="server">
<asp:ListItem Text=1 Value=1></asp:ListItem>
<asp:ListItem Text=1 Value=1></asp:ListItem>
<asp:ListItem Text=1 Value=1></asp:ListItem>
</asp:ListBox>
<asp:Button ID="Button2" runat="server" Text="Button" OnClick="Button2_Click" /