I'm having a problem with rebinding data in a ListView right after OnItemCommand is triggered from a button in the ItemTemplate. When the button is clicked, I am deleting the data in the row (which successfully occurs) but when I try to rebind the data in the ListView nothing happens until the page is refreshed.
I know that a suggested solution is to have an ObjectDataSource and to just declare what to do upon deletion in there but I need a solution for data binding data in the code-behind. (Note that I have the delete function working and only need a solution for the page to postback and to repopulate the ListView right after.
<asp:ListView ID="lv_PagePosts" runat="server" ItemPlaceholderID="itemContainer" OnItemCommand="lv_PagePosts_ItemCommand">
<asp:PlaceHolder ID="itemContainer" runat="server"></asp:PlaceHolder>
<asp:LinkButton ID="lb_delete" runat="server" Font-Bold="false" Visible="false" CommandName="Delete">Delete</asp:LinkButton>
protected void lv_PagePosts_ItemCommand(object source, ListViewCommandEventArgs e)
if (e.CommandName == "Delete")
GamingNetworkDBDataContext db = new GamingNetworkDBDataContext();
Label lbl_postID = (Label)e.Item.FindControl("lbl_postID");
int postID = Convert.ToInt32(lbl_postID.Text);
var p = from pp in db.PagePosts
where pp.postID == postID
//rebind the data in ListView