【问题标题】:how to implement if statements on radio button list?如何在单选按钮列表上实现 if 语句?
【发布时间】:2016-02-21 07:42:48
【问题描述】:

我有一个电子商务网站,在我的“立即订购”页面中,我有 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]));


        }
    }

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

【问题讨论】:

    标签: asp.net radiobuttonlist


    【解决方案1】:

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

    这里有一个代码示例

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

    希望对你有帮助,别忘了接受我的回答:)

    【讨论】:

      猜你喜欢
      • 2013-07-21
      • 1970-01-01
      • 2012-11-21
      • 2016-08-04
      • 2016-03-19
      • 2016-03-19
      • 2021-07-03
      • 2015-09-13
      • 2023-03-12
      相关资源
      最近更新 更多