vendredi 31 juillet 2015

Refresh Listview after delete a row into table

Into my asp.net application there is a Listview called ( pendingorderLV ) shown the pending orders of the customer and it include a delete button to delete the orders, what i am looking for is how i can make the listview refresh it self when the user click on each delete button and show the remain orders.

the listview behind code where user can reach it from a button into my application called: gotovieworder

 protected void gotovieworder_Click(object sender, EventArgs e)
    {


        MultiView1.ActiveViewIndex = 7;

        if (Session["UsrNme"] != null)
        {
            var user = Session["UsrNme"];
            using (var UsOrderCon = new SqlConnection(sc))
            {
                UsOrderCon.Open();

                string chksUsOrderstring = "Select count (*) from ShoppingCart where UID=@chkUID";

                SqlCommand ChkUsOrderCMD = new SqlCommand(chksUsOrderstring, UsOrderCon);

                ChkUsOrderCMD.Parameters.AddWithValue("@chkUID", user);

                var orderExists = (Int32)ChkUsOrderCMD.ExecuteScalar() > 0;

                if (orderExists)
                {

                    pendingorderpanel.Visible = true;
                    SqlDataAdapter UsOrderADPA = new SqlDataAdapter("SELECT [UID], [Product], [DateAdded], [PayMeth], [ProdDesc], [CartID] FROM [ShoppingCart] WHERE  [UID] = @uSer ", sc);

                    UsOrderADPA.SelectCommand.Parameters.AddWithValue("@uSer", Convert.ToString(Session["UsrNme"]));

                    DataSet UsOrderDST = new DataSet();
                    UsOrderADPA.Fill(UsOrderDST);
                    pendingorderLV.DataSource = UsOrderDST.Tables[0];
                    pendingorderLV.DataBind();
                    pendingorderpanel.Visible = true;


                }
                else
                {
                    UsexcOrderpanel.Visible = true;
                    UsOrderlbl.Text = "You dont have any orders, if you would like to become a premium user";
                }
            }
        }
    }

And the delete button inside the listview behind code is:

protected void deltPendOrder_Command(object sender, CommandEventArgs e)
    {
        using (SqlConnection DeltPndOrdSQLCon = new SqlConnection(sc))
        {
            int OrdPendID = Convert.ToInt32(e.CommandArgument);

            System.Data.SqlClient.SqlCommand DeltPendOrdcmd = new System.Data.SqlClient.SqlCommand();
            DeltPendOrdcmd.CommandType = System.Data.CommandType.Text;

            DeltPendOrdcmd.CommandText = "DELETE FROM ShoppingCart WHERE CartID = @CartID";

            DeltPendOrdcmd.Parameters.AddWithValue("@CartID", OrdPendID);
            DeltPendOrdcmd.Connection = DeltPndOrdSQLCon;
            DeltPndOrdSQLCon.Open();

            DeltPendOrdcmd.ExecuteNonQuery();
            DeltPndOrdSQLCon.Close();
            viewmsgView.Visible = true;
        }


    }

Aucun commentaire:

Enregistrer un commentaire