如何在asp.net中使用jquery删除Listview项

如何在asp.net中使用jquery删除Listview项,jquery,asp.net,Jquery,Asp.net,我正在asp.net中开发一个应用程序,其中有一个Listview,该Listview中有另一个Listview。在内部listview中,我有一个linkbutton,用于删除内部listview的项目。我想使用jquery删除内部listview的项。我程序的设计部分是: <asp:ListView ID="ListView5" runat="server" OnItemDataBound="ListView5_ItemDataBound"> <ItemTemplate&

我正在asp.net中开发一个应用程序,其中有一个Listview,该Listview中有另一个Listview。在内部listview中,我有一个linkbutton,用于删除内部listview的项目。我想使用jquery删除内部listview的项。我程序的设计部分是:

<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>

删除

删除内部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);
        }
    }
protectedvoid lbtnDelete\u单击(对象发送方,事件参数e)
{
尝试
{
ListViewDataItem gdr=(ListViewDataItem)((控制)发送方).NamingContainer;
LinkButton linkComment=(LinkButton)gdr.FindControl(“lbtnDelete”);
long ID=Convert.ToInt64(linkComment.CommandArgument.ToString());
retval=newprocess_wallcoment().DeleteComment(ID);
如果(返回值>0)
{
Bind();
响应。写入(“警报(‘已删除’)”);
}
}
捕获(例外情况除外)
{
投掷(ex);
}
}

但我的代码会在删除过程中刷新页面。我想使用jquery删除内部listview的项。请帮助我。

那么您想删除包含删除按钮的列表吗

您可以尝试以下示例:

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

我还想从数据库中删除项,并且在删除后,我想使用jquery将listview与datatable的datasource绑定。是否可能。如果是,然后,请帮助我这样做。您可以创建一个单独的asp.net页面,该页面将从查询字符串中接受列表id,并对数据库执行删除操作,然后在其中重新加载新列表。然后,您可以使用查询字符串从函数removeList()对该页面进行ajax调用,作为响应,读取在另一个页面上创建的新列表并将其显示出来。我不是asp.net人员,但我认为asp:update面板应该可以正常工作
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.
}