I have two list boxes among which one is source and other is destination.
I want to transfer the selected item to the destination list box after the button click event.
I have searched over the internet and found the sample from here. But in my case its not working.
My ASP source file is :
<asp:Table ID="tbvl" Width="100%" runat="server">
<asp:TableRow>
<asp:TableCell Width="45%">
<asp:ListBox ID="lstsource" CssClass="uppercase" runat="server" Width="100%" Height="140" SelectionMode="Multiple"></asp:ListBox>
</asp:TableCell>
<asp:TableCell Width="10%" HorizontalAlign="Center" Height="100%">
<asp:Table ID="Table1" runat="server" Height="100%">
<asp:TableRow>
<asp:TableCell Height="25%"><asp:Button ID="btnsd" CssClass="button" runat="server" Text=">>" Width="40" /></asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell Height="25%"><asp:Button ID="btnds" runat="server" CssClass="button" Text="<<" Width="40" /></asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell Height="25%"><asp:Button ID="btnallsd" runat="server" CssClass="button" Text=">" Width="40" /></asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell Height="25%"><asp:Button ID="btnallds" runat="server" CssClass="button" Text="<" Width="40" /></asp:TableCell>
</asp:TableRow>
</asp:Table>
</asp:TableCell>
<asp:TableCell Width="50%">
<asp:ListBox ID="lstdestination" runat="server" CssClass="uppercase" Width="100%" Height="140" SelectionMode="Multiple"></asp:ListBox>
</asp:TableCell>
</asp:TableRow>
</asp:Table>
And my Click()
event is;
void btnallsd_Click(object sender, EventArgs e)
{
for (int i = lstsource.Items.Count - 1; i >= 0; i--)
{
if (lstsource.Items[i].Selected)
{
lstdestination.Items.Add(lstsource.Items[i]);
lstdestination.ClearSelection();
lstsource.Items.Remove(lstsource.Items[i]);
}
}
}
When I click the button page is only getting refreshed but the items are not added to the destination list box.
What should I do to get proper output.
Please help.