Reputation: 2354
I want when click on button in list view items ,this item is deleted. list view codes like this:
<asp:ListView ID="ListView1" runat="server" OnItemCommand="ListView1_ItemCommand" >
<LayoutTemplate>
<asp:PlaceHolder runat="server" ID="itemPlaceholder"></asp:PlaceHolder>
</LayoutTemplate>
<ItemTemplate>
<div data-target="#modal_result" data-toggle="modal" onclick="func_getData();" onmouseout="javascript:func_UN_highlight(this);" onmouseover="javascript: func_highlight(this);">
<p>نام کتاب : <%#(Eval("name_book")) %></p>
<p>نویسنده : <%#(Eval("author_book")) %></p>
<div class="q">
<p>ویرایش : <%#(Eval("edition_book")) %></p>
</div>
<div class="q">
<p>قیمت : <%#(Eval("price_book")) %></p>
</div>
<asp:Image ID="Image1" runat="server" ImageUrl='<%#(Eval("image")) %>'/>
<asp:Button ID="Bbtn_delete" runat="server" CommandArgument='<%# Eval("id_book") %>' CommandName="delete" CausesValidation="True" UseSubmitBehavior="False" CssClass="btn btn-danger" Text="حــذف" />
<asp:Button ID="btn_edit" runat="server" CommandArgument='<%# Eval("id_book") %>' CommandName="edit" CausesValidation="True" UseSubmitBehavior="False" CssClass=" btn btn-warning" Text="ویرایش" />
<br>
</div>
</ItemTemplate>
</asp:ListView>
and itemcommand event like this:
protected void ListView1_ItemCommand(object sender, System.Web.UI.WebControls.ListViewCommandEventArgs e)
{
if (e.CommandName == "delete")
{
string idbook = e.CommandArgument.ToString();
T_bookBusiness bookBusiness = new T_bookBusiness();
T_book book = new T_book();
book.IdBook = long.Parse(idbook);
bookBusiness.Delete(book);
//پر کردن دوباره لیست ویو
DataBind();
}
}
Now when click on the Delete button Item is deleted but show this error :The ListView 'ListView1' raised event ItemDeleting which wasn't handled. Please help.
Upvotes: 1
Views: 361
Reputation: 686
Instead of CommandName="delete" use CommandName="delete_row" or anything other than "delete". Same is applicable for "edit".
Upvotes: 2