The button event in listview adds the method

  • 2020-05-19 04:32:39
  • OfStack

1.
 
<asp:ListView ID="lvBalance" runat="server" > 
<LayoutTemplate> 
<div id="listDiv" style="width:100%;overflow-y:auto;"> 
<table border=0 cellpadding=0 cellspacing=0 style="float:left;table-layout:fixed;" class="datagrid-body easydatagrid"> 
<asp:PlaceHolder id=itemPlaceholder runat=server/> 
</table> 
<div id="div999" style='display: none; width: 200px;' class="div2"></div> 
</div> 
</LayoutTemplate> 
<ItemTemplate> 
<tr><td> 
<asp:LinkButton ID="lb_delete" runat="server" CommandArgument='<%#Eval("ItemCode")%>' OnClientClick="return confirm(' Are you sure to delete this message? ');" onclick="lb_delete_Click" Text=" delete "></asp:LinkButton> 
<</td>/tr> 
</ItemTemplate> 
</asp:ListView> 

2.
 
protected void lb_delete_Click(object sender, EventArgs e) 
{ 
LinkButton lbdelete = (LinkButton)sender; 
BLLAccount bll_updateBalance = new BLLAccount(); 
if (hd_vehiclecode.Value != "" && lbdelete.CommandArgument != "") 
{ 
if (bll_updateBalance.deleteBalance(hd_vehiclecode.Value, lbdelete.CommandArgument) == true) 
{ 
this.ClientScript.RegisterStartupScript(this.GetType(), this.Title, "alert(' Delete the success !');", true); 
Datebind(); 
} 
else 
{ 
this.ClientScript.RegisterStartupScript(this.GetType(), this.Title, "alert(' Delete failed !');", true); 
} 
} 
} 

Related articles: