有沒有一種方法可以確保用戶從(按鈕列表)中選擇單選按鈕只能從每個組中選擇一個按鈕?我有一個網頁表單,可以根據重量,城市和運輸方式計算運費。我的代碼是不是風格還沒有,但是這是我試圖每磅 孟菲斯$ $ 1.50 2.35 亞特蘭大每磅2天交付如何製作多個單選按鈕列表,以便每個組只能檢查一個按鈕
位置5天交貨的要點$ 2.75 $ 4.50
在我的形式向用戶點擊孟菲斯,然後點擊與亞特蘭大對應的按鈕5天,項目權重乘以2.75美元,並將最終成本發送到文本框。現在,用戶可以選擇所有的單選按鈕,但是它們應該在整個表單中對齊。見下面
<ASP Code>
<%@ Page Language="VB" AutoEventWireup="false"
CodeFile="Default.aspx.vb" Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
Please select the appropriate shipping information</div>
<div>
<br />
Weight of Item
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<br />
<br />
Ship To Location
<br />
<br />
<asp:RadioButtonList ID="RadioButtonList1" runat="server">
<asp:ListItem>Memphis</asp:ListItem>
<asp:ListItem>Cincinnati</asp:ListItem>
<asp:ListItem>San Francisco</asp:ListItem>
<asp:ListItem>Las Vegas</asp:ListItem>
<asp:ListItem>New York</asp:ListItem>
</asp:RadioButtonList>
<br />
Cost Per Pound 5-day delivery<br />
<br />
<asp:RadioButtonList ID="RadioButtonList2" runat="server">
<asp:ListItem>$1.12</asp:ListItem>
<asp:ListItem>$0.92</asp:ListItem>
<asp:ListItem>$2.45</asp:ListItem>
<asp:ListItem>$1.21</asp:ListItem>
<asp:ListItem>$2.00</asp:ListItem>
</asp:RadioButtonList>
<br />
Cost Per Pound 2-day delivery<br />
<asp:RadioButtonList ID="RadioButtonList3" runat="server">
<asp:ListItem>$1.65</asp:ListItem>
<asp:ListItem>$1.45</asp:ListItem>
<asp:ListItem>$2.70</asp:ListItem>
<asp:ListItem>$1.41</asp:ListItem>
<asp:ListItem>$2.70</asp:ListItem>
</asp:RadioButtonList>
<br />
Cost Per Pound Next day delivery<br />
<asp:RadioButtonList ID="RadioButtonList4" runat="server">
<asp:ListItem>$1.92</asp:ListItem>
<asp:ListItem>$1.88</asp:ListItem>
<asp:ListItem>$3.00</asp:ListItem>
<asp:ListItem>$1.87</asp:ListItem>
<asp:ListItem>$2.99</asp:ListItem>
</asp:RadioButtonList>
<br />
<br />
<asp:Button ID="Button1" runat="server" Text="Calculate
Shipping Costs" />
<asp:Button ID="Button2" runat="server" Text="Clear Selections"
/>
<br />
<br />
<br />
Total Shipping Costs:
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<br />
</div>
</form>
</body>
</html>
<VB Code>
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles
Button1.Click
'variables to hold weight and shipping cost
Dim itemWeight, shipCost As Double
'get itemWeight from text box
itemWeight = Val(TextBox1.Text)
'memphis shipping
If RadioButtonList1.SelectedIndex = 0 And
RadioButtonList2.SelectedIndex = 0 Then
shipCost = (itemWeight * 1.12)
TextBox2.Text = shipCost
ElseIf RadioButtonList1.SelectedIndex = 0 And
RadioButtonList3.SelectedIndex = 0 Then
shipCost = (itemWeight * 1.65)
TextBox2.Text = shipCost
ElseIf RadioButtonList1.SelectedIndex = 0 And
RadioButtonList4.SelectedIndex = 0 Then
shipCost = (itemWeight * 1.92)
TextBox2.Text = shipCost
End If
'cincinnati shipping
If RadioButtonList1.SelectedIndex = 1 And
RadioButtonList2.SelectedIndex = 1 Then
shipCost = (itemWeight * 0.92)
TextBox2.Text = shipCost
ElseIf RadioButtonList1.SelectedIndex = 1 And
RadioButtonList3.SelectedIndex = 1 Then
shipCost = (itemWeight * 1.45)
TextBox2.Text = shipCost
ElseIf RadioButtonList1.SelectedIndex = 1 And
RadioButtonList4.SelectedIndex = 1 Then
shipCost = (itemWeight * 1.88)
TextBox2.Text = shipCost
End If
'San Francisco Shipping
If RadioButtonList1.SelectedIndex = 2 And
RadioButtonList2.SelectedIndex = 2 Then
shipCost = (itemWeight * 2.45)
TextBox2.Text = shipCost
ElseIf RadioButtonList1.SelectedIndex = 2 And
RadioButtonList3.SelectedIndex = 2 Then
shipCost = (itemWeight * 2.7)
TextBox2.Text = shipCost
ElseIf RadioButtonList1.SelectedIndex = 2 And
RadioButtonList4.SelectedIndex = 2 Then
shipCost = (itemWeight * 3.0)
TextBox2.Text = shipCost
End If
'Las Vegas Shipping
If RadioButtonList1.SelectedIndex = 3 And
RadioButtonList2.SelectedIndex = 3 Then
shipCost = (itemWeight * 1.21)
TextBox2.Text = shipCost
ElseIf RadioButtonList1.SelectedIndex = 3 And
RadioButtonList3.SelectedIndex = 3 Then
shipCost = (itemWeight * 1.41)
TextBox2.Text = shipCost
ElseIf RadioButtonList1.SelectedIndex = 3 And
RadioButtonList4.SelectedIndex = 4 Then
shipCost = (itemWeight * 1.87)
TextBox2.Text = shipCost
End If
'New York Shipping
If RadioButtonList1.SelectedIndex = 4 And
RadioButtonList2.SelectedIndex = 4 Then
shipCost = (itemWeight * 2.0)
TextBox2.Text = shipCost
ElseIf RadioButtonList1.SelectedIndex = 4 And
RadioButtonList3.SelectedIndex = 4 Then
shipCost = (itemWeight * 2.7)
TextBox2.Text = shipCost
ElseIf RadioButtonList1.SelectedIndex = 4 And
RadioButtonList4.SelectedIndex = 4 Then
shipCost = (itemWeight * 2.99)
TextBox2.Text = shipCost
End If
End Sub
Protected Sub Button2_Click(sender As Object, e As EventArgs) Handles
Button2.Click
For Each ctrl As Control In form1.Controls
If ctrl.[GetType]() = GetType(TextBox) Then
DirectCast(ctrl, TextBox).Text = String.Empty
ElseIf ctrl.[GetType]() = GetType(RadioButtonList) Then
DirectCast(ctrl, RadioButtonList).ClearSelection()
End If
Next
End Sub
End Class
是的,沒錯。他們可以通過選擇另一個選項來改變選擇。 – allendks45