0

我正在研究asp.net 中的一个应用程序,其中我有一个Listview,并且在该listview 中有另一个listview。在内部列表视图中,我有一个链接按钮,用于删除内部列表视图的项目。我想删除内部列表视图使用 jquery 的项目。我的程序的设计部分是:

<asp:ListView ID="ListView5" runat="server" OnItemDataBound="ListView5_ItemDataBound">
 <ItemTemplate>
   <li>
      <asp:UpdatePanel ID="upcom" runat="server" UpdateMode="Conditional">
      <ContentTemplate>
   <asp:Image runat="server" Style="width: 50px; height: 50px;" ID="Image1" ImageUrl='<%#Eval("Image") %>' />
  <asp:HiddenField ID="lblWallID" runat="server" Value='<%#Eval("Wall_ID") %>'></asp:HiddenField>
  <p>
     <h3>
          <a href="Profile.aspx?ID=<%#Eval("UID") %>">
          <asp:Label ID="lbl1" runat="server" Text='<%#Eval("Full_Name") %>'></asp:Label>
           </a>
    </h3>
 </p>
 <p>
   <asp:Label ID="Label1" runat="server" Text='<%#Eval("Wall_Content") %>'></asp:Label>
</p>
<p>
   <asp:Label ID="lblTime" CssClass="time-text" runat="server" Text='<%#Eval("TimeAgo") %>'></asp:Label>
   <asp:LinkButton ID="btnClick" runat="server" Text="Comment" OnClick="btnClick_Click" CommandArgument='<%#Eval("Wall_ID") %>' CommandName="Comment"></asp:LinkButton>
</p>
<p>
    <ul>
        <asp:ListView ID="listWallComments" runat="server" >
        <ItemTemplate>
         <li>
            <asp:Label ID="lblWallComment" runat="server" Text='<%#Eval("Comments") %>'></asp:Label>:-
            <a href="Profile.aspx?ID=<%#Eval("User_ID") %>">
            <asp:Label ID="lblFullname11" runat="server" CommandName="Profile" CommandArgument='<%#Eval("User_ID") %>' Text='<%#Eval("Full_Name") %>'></asp:Label>
            </a>
            <asp:LinkButton ID="lbtnDelete" runat="server" CommandArgument='<%#Eval("Comment_ID") %>' onclick= OnClientClick="Confirm('Are u sure to delete?') %>)">Delete</asp:LinkButton>                                                              
                                                                                   </li>
    </ItemTemplate>
    </asp:ListView>
    </ul>
    </p>
</ContentTemplate>
  <Triggers>
      <asp:AsyncPostBackTrigger ControlID="btnClick" EventName="Click" />
 </Triggers>
</asp:UpdatePanel>
</li>
</ItemTemplate>
</asp:ListView>

删除内部列表视图项的代码是:

protected void lbtnDelete_Click(object sender, EventArgs e)
    {
        try
        {
            ListViewDataItem gdr = (ListViewDataItem)((Control)sender).NamingContainer;

                LinkButton linkComment = (LinkButton)gdr.FindControl("lbtnDelete");
                long ID = Convert.ToInt64(linkComment.CommandArgument.ToString());
                retval = new Process_WallComment().DeleteComment(ID);
                if (retval > 0)
                {
                    Bind();
                    Response.Write("<script>alert('Deleted')</script>");
                }

        }
        catch (Exception ex)
        {
            throw(ex);
        }
    }

但是我的代码在删除过程中刷新了页面。我想使用 jquery 删除内部列表视图的项目。请帮助我。

4

1 回答 1

0

所以你想删除包含删除按钮的列表吗?

你可以试试这个示例:

<li>
//your other markup here
// then the delete button
<button onclick="removeList(this)"> </button>
</li>

javascript函数

function removeList(btn){
// add delete confirmation here , if true continue else return from the function from here.
btn.parent().remove();
// this will remove the parent element of the button. ie the list item.
//do not add "runat=server" as this is client side operation and the page should not post //back.
}
于 2013-10-20T11:42:09.283 回答