如何在单选按钮列表上实现if语句?

时间:2016-02-20 13:06:22

标签: asp.net radiobuttonlist

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

我知道它的代码:

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]));


        }
    }

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

1 个答案:

答案 0 :(得分:0)

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

这里有一个代码示例

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

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