• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3167
  • Last Modified:

The ListView raised event ItemUpdating which wasn't handled.

Hi There,

I have a list view that I'm calling the ItemCommand event on. It runs through the ItemCommand event's code ok but then it throws an exception The ListView XXXX raised event ItemUpdating which wasn't handled. So I added in the ItemUpdating event but to no avail. The exception is till being thrown. What else do I need to add ? The list is being populated on page load and I rebind the list after the item command.

    protected void lstShoppingCart_ItemCommand(object sender, ListViewCommandEventArgs e)
        {
            HttpSessionState ss = HttpContext.Current.Session;
            if (ss != null)
            {
                if (!String.IsNullOrEmpty(ss.SessionID))
                {
                    using (CartRep cart = new CartRep())
                    {
                        using (something context = new (somethingcontext ())
                        {

                            var q = cart.getthetData(ss.SessionID);
                             int cmdArg = int.Parse(e.CommandArgument.ToString());
                            if (e.CommandName == "Remove")
                            {
                               
                                if (cmdArg >= 0)
                                {
                                    string strRTesponseText = DeleteProduct(cmdArg);
                                    lblstatus.Text = strRTesponseText;
                                    lstShoppingCart.DataSource = q;
                                    lstShoppingCart.DataBind();
                                }
                            }
                            else if (e.CommandName == "Update")
                            {
                                if (cmdArg >= 0) {
                                 
                                   

                                        var dbcartInfo = context.tblCartSessions_Products
                                    .Where(w => w.ID == cmdArg)
                                    .SingleOrDefault();

                                        if (dbcartInfo != null)
                                        {
                                         
                                            dbcartInfo.quantity = cmdArg;
                                            context.SaveChanges();
                                        }

                                        lstShoppingCart.EditIndex = int.Parse(e.CommandArgument.ToString());
                                        lstShoppingCart.DataSource = q;
                                        lstShoppingCart.DataBind();
                                 
                           
                                }
                           
                            }

                        }
                    }
                }
            }
        }
0
schcobole
Asked:
schcobole
1 Solution
 
informaniacCommented:
Just add a blank itemupdating events.

<asp:ListView ID="lstShoppingCart" runat="server" OnItemUpdating="lstShoppingCart_ItemUpdating"></asp:ListView>

protected void lstShoppingCart_ItemUpdating(object sender, ListViewUpdateEventArgs e)
        {

        }

Open in new window

0
 
Alan WarrenCommented:
wondering if your datasource 'q' is being persisted and if you need a handler for ItemUpdating to handle the custom databinding. I don't expect this would be an issue if you used a SqlDataSource, but using a custom datasource...


protected void lstShoppingCart_ItemUpdating(object sender, System.Web.UI.WebControls.ListViewUpdateEventArgs e)
{
        lstShoppingCart.EditIndex = e.ItemIndex;
        lstShoppingCart.DataSource = SomeData; // q maybe...
        lstShoppingCart.DataBind();
}

Open in new window

Alan
0
 
schcoboleAuthor Commented:
I can't believe it was that easy.
0

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now