This is a migrated thread and some comments may be shown as answers.

Delete item based on command name

1 Answer 26 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
L
Top achievements
Rank 1
L asked on 22 Aug 2014, 04:00 PM
hi

How do I remove or delete item from listbox using command name? Thanks a lot

Here is my code:

<telerik:RadListBox ID="lbProductList" runat="server" Width="100%"  EnableViewState="true" ViewStateMode="Enabled" Skin="Metro" style="top: 0px; left: 0px" AutoPostBack="True" EnableDragAndDrop="True">
                  <ItemTemplate>
                        <table>
                                <tr>
                                    <td class="leftbox"><asp:Image ID="Image1" CssClass="circularsmall" runat="server" EnableViewState="true" ImageUrl='<%# "~/images.ashx?id=" + Eval("PhotoThumb")%>' /></td>
                                    <td class="rightbox"><div class="semibold"  style="word-wrap:break-word"><%# Eval("ProductName")%></div>
                                    <div>
                                    <asp:LinkButton ID="lnkDelete" CommandName="remove" Text="Remove" style="text-decoration:none;color:darkgray;font-size:smaller" runat="server"></asp:LinkButton></div>
                                    </td>
                             </tr>
                          </table>
                     </ItemTemplate>
                 </telerik:RadListBox>

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 25 Aug 2014, 06:16 AM
Hi,

I guess you want to delete the selected item on click of 'Remove' button. Try to attach the onClick event for the LinkButton and do the following C# code snippet which works fine at my end.

C#:
protected void lnkDelete_Click(object sender, EventArgs e)
{
    RadListBoxItem item = (RadListBoxItem)lbProductList.SelectedItem;
    lbProductList.Items.Remove(item);
}

Please elaborate your requirement if it doesn't help.
Thanks,
Princy.
Tags
ListBox
Asked by
L
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Share this question
or