2016-02-20 49 views
-1

我有一个电子商务网站,并在我的订单现在页面,我有3个单选按钮列表,即:现金支付,付款gatewat和银行存款。我打算做的是当你选择现金付款时,它会引导你进入一个现金支付页面,当你去付款网关时,它会引导你到另一个页面等等。如何在单选按钮列表上实现if语句?

我知道它的代码:

if 
(rblPaymentMethod.SelectedItem.Value="1") 
{ 
code here: 
} 

但是拥有这些代码,我不知道放在哪里。

protected void btnPlaceOrder_Click(object sender, EventArgs e) 
    { 
     string productids = string.Empty; 
     DataTable dt; 
     if (Session["MyCart"] != null) 
     { 
      dt = (DataTable)Session["MyCart"]; 

      decimal totalPrice, totalProducts; 
      bool totalPriceConversionResult = decimal.TryParse(txtTotalPrice.Text, out totalPrice), totalProductsConversionResult = decimal.TryParse(txtTotalProducts.Text, out totalProducts); 


      ShoppingCart k = new ShoppingCart() 
      { 
       CustomerName = txtCustomerName.Text, 
       CustomerEmailID = txtCustomerEmailID.Text, 
       CustomerAddress = txtCustomerAddress.Text, 
       CustomerPhoneNo = txtCustomerPhoneNo.Text, 
       TotalProducts = totalProductsConversionResult ? Convert.ToInt32(totalProducts) : 0, 
       TotalPrice = totalPriceConversionResult ? Convert.ToInt32(totalPrice) : 0, 
       ProductList = productids, 
       PaymentMethod = rblPaymentMethod.SelectedItem.Text 

      }; 
      DataTable dtResult = k.SaveCustomerDetails(); 

      for (int i = 0; i < dt.Rows.Count; i++) // loop on how many products are added by the user 
      { 
       ShoppingCart SaveProducts = new ShoppingCart() 
       { 
        CustomerID = Convert.ToInt32(dtResult.Rows[0][0]), 
        ProductID = Convert.ToInt32(dt.Rows[i]["ProductID"]), 
        TotalProducts = Convert.ToInt32(dt.Rows[i]["ProductQuantity"]), 
       }; 
       SaveProducts.SaveCustomerProducts(); 
      } 
      lblTransactionNo.Text = "Your Transaction Number: " + dtResult.Rows[0][0]; 

      pnlOrderPlaceSuccessfully.Visible = true; 
      pnlCheckOut.Visible = false; 
      pnlCategories.Visible = false; 
      pnlMyCart.Visible = false; 
      pnlEmptyCart.Visible = false; 
      pnlProducts.Visible = false; 

      SendOrderPlacedAlert(txtCustomerName.Text, txtCustomerEmailID.Text, Convert.ToString(dtResult.Rows[0][0])); 


     } 
    } 

任何想法将不胜感激。谢谢!

回答

0

遍历列表项然后添加你的if语句...

在这里你会得到一个代码示例

protected void Button1_Click(object sender, EventArgs e) 
    { 
     foreach (ListItem li in RadioButtonList1.Items) 
     { 
      if (li.Selected) 
      { 
       Label1.Text = RadioButtonList1.SelectedValue ; 
      } 
     } 
    } 

希望它可以帮助你,不要忘记为最好接受我的答案: )