title: response redirect after if or else
body: <p>I have if and else statement in my ListView data</p>
  
  <pre><code>void insert() {
  
      con.Open();
      SqlCommand cmd = new SqlCommand();
      cmd.Connection = con;
      cmd.CommandText = "INSERT INTO SO VALUES (@Status, @DateOrdered, @UserID, @PaymentTerms, @ShippingTerms, @ShippingMethod, @DeliveryDate)";
      cmd.Parameters.AddWithValue("@Status", "NEW");
      cmd.Parameters.AddWithValue("@DateOrdered", DateTime.Now);
      cmd.Parameters.AddWithValue("@UserID", Session["userid"].ToString());
      cmd.Parameters.AddWithValue("@PaymentTerms", ddlPaymentTerms.SelectedValue);
      cmd.Parameters.AddWithValue("@ShippingTerms", lbShippingTerms.Text);
      cmd.Parameters.AddWithValue("@ShippingMethod", ddlShippingMethod.Text);
      cmd.Parameters.AddWithValue("@DeliveryDate", txtDeliveryDate.Text);
      cmd.ExecuteNonQuery();
      con.Close();
  
      Response.Redirect("/Users/Orders/SO/Default.aspx");
  }
  
  protected void btnCheckout_Click(object sender, EventArgs e) {
  
      foreach(ListViewItem Items in lvCart.Items) {
          //for
          //           (int i = 0; i &lt; lvCart.Items.Count; i++)
          //{
          int ProductID = 0;
          Label lbproductid = (Label) Items.FindControl("lbproductid");
          ProductID = Convert.ToInt32(lbproductid.Text);
  
          int Available = 0;
          Label avail = (Label) Items.FindControl("avail");
          Available = Convert.ToInt32(avail.Text);
  
          int Quantity = 0;
          TextBox txtQty = Items.FindControl("txtQty") as TextBox;
          Quantity = Convert.ToInt32(txtQty.Text);
          //SqlDataReader dr = cmd.ExecuteReader();
          if (Quantity &gt; Available) {
             error.Visible = true;
             con.Close();
          } else {
             insert();
             con.Close();
          }
  
          con.Close();
      }
      con.Close();
      Response.Redirect("/Users/Cart/Default.aspx");
  }
  </code></pre>
  
  <p>what i want to happen is when It is IF (Quantity > Available)
  Stays in the page and shows error</p>
  
  <p>when else redirect to the next page</p>
  
  <p>I tried and whenever under if still redirects to the next page.</p>
  
  <p>What's wrong and how can I fix it?</p>