Delete item based on command name

2 posts, 0 answers
  1. L
    L avatar
    295 posts
    Member since:
    Apr 2008

    Posted 22 Aug 2014 Link to this post

    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>
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 25 Aug 2014 in reply to L Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top