Delete Row from asp:Repeater with Button

6.6k views Asked by At

My first question that's not homework related, feelsgood.jpg

asp C# project with RavenDB

I'm trying to delete rows from a repeater using this button at the end of a row:

<asp:Button ID="Delete" runat="server" Text="Delete" class="btn btn-danger" CommandName="Delete" CommandArgument='<%# Eval("PartNumber") %>'/>

Using this code behind it. I put a breakpoint on the if statement and it never hits it like it's not getting into this function at all.

 protected void repProducts_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        if (e.CommandName == "Delete") //breakpoint on this line
        {
            int partNum = Convert.ToInt32(e.CommandArgument);

            session.Delete(partNum); 
            session.SaveChanges();
        }
    }

I checked console and I don't have any errors there, just warnings;

Synchronous XMLHttpRequest on the main thread is deprecated Setting 'XMLHttpRequest.withCredentials' for synchronous requests is deprecated.

I don't know if those are useful or not. Does anyone know why my post back never seems to hit that function?

1

There are 1 answers

1
Jordan Wayne Crabb On

I found the issue, I forgot to wrap the data binding with "if(!isPostBack)"

protected void Page_Load(object sender, EventArgs e)
    {
        List<Product> prods = session.Query<Product>().ToList();

        if(!IsPostBack)
        {
            repProducts.DataSource = prods;
            repProducts.DataBind();
        }
    }