I am using a asp.net listbox. I have two buttons one to add items to listbox and another to remove. I am using javascript function to remove items from the listbox. When I add to the listbox after removing. The removed items are also getting added.
<asp:ListBox ID="sLstbox" runat="server" Width="250px" Height="150px" TabIndex="10"></asp:ListBox>
<asp:LinkButton ID="sLbtnAdd" runat="server" ></asp:LinkButton>
<a href="#" id="hAncRemove" runat="server" onclick="fncRemoveItems();">Remove</a>
function fncRemoveItems()
{
var i;
var strIDs="";
var items = document.getElementById("sLstbox");
alert(items.options.length);
for (i = items.options.length - 1; i >= 0; i--)
{
if (items.options[i].selected)
items.remove(i);
}
}
IN code
Protected Sub sLbtnAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles sLbtnAdd.Click
Dim li As New ListItem
li.Value = "1"
li.Text = "test"
sLstbox.Items.Add(li)
End Sub