我有一个像下面的点表,它有下拉列表和2个单选按钮列表。选择值后,我想显示每个文本框中的倍数值和总数。
例如
DDL1 * RB1 * RB2 =(THE VALUE1)
DDL2 * RB3 * RB4 =(THE VALUE2)
总计:(THE VALUE1)+(THE VALUE2)
Example.aspx
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<br />
<h3 style="text-align: center">Point Table</h3>
<br />
<table style="width:100%;">
<tr>
<td style="width:73px;">Section</td>
<td style="width:145px;">WEIGHTED SCORE(A)</td>
<td>FIELD(B)</td>
<td>FIELD(C)</td>
<td>FIELD(D) D=AxBxC</td>
</tr>
<tr>
<td style="width: 73px">Section A</td>
<td style="width: 145px">
<asp:DropDownList ID="DropDownList1" runat="server" Height="22px" Width="80px">
<asp:ListItem Selected="True">Select</asp:ListItem>
<asp:ListItem>5</asp:ListItem>
<asp:ListItem>10</asp:ListItem>
<asp:ListItem>15</asp:ListItem>
</asp:DropDownList>
</td>
<td>
<asp:RadioButtonList ID="RadioButtonList1" runat="server" Height="16px" RepeatDirection="Horizontal" Width="270px">
<asp:ListItem Value="0,4"></asp:ListItem>
<asp:ListItem Value="0,7"></asp:ListItem>
<asp:ListItem Value="1"></asp:ListItem>
</asp:RadioButtonList>
</td>
<td>
<asp:RadioButtonList ID="RadioButtonList2" runat="server" Height="23px" RepeatDirection="Horizontal" Width="383px">
<asp:ListItem Value="0,6"></asp:ListItem>
<asp:ListItem Value="0,7"></asp:ListItem>
<asp:ListItem Value="0,8"></asp:ListItem>
<asp:ListItem Value="0,9"></asp:ListItem>
<asp:ListItem Value="1"></asp:ListItem>
</asp:RadioButtonList>
</td>
<td>
<asp:TextBox ID="TextBox1" runat="server" Width="63px"></asp:TextBox>
</td>
</tr>
<tr>
<td style="width: 73px">
Section B</td>
<td style="width: 145px">
<asp:DropDownList ID="DropDownList2" runat="server" Height="22px" Width="80px">
<asp:ListItem Selected="True">Select</asp:ListItem>
<asp:ListItem>5</asp:ListItem>
<asp:ListItem>10</asp:ListItem>
<asp:ListItem>15</asp:ListItem>
</asp:DropDownList>
</td>
<td>
<asp:RadioButtonList ID="RadioButtonList3" runat="server" Height="16px" RepeatDirection="Horizontal" Width="270px">
<asp:ListItem Value="0,4"></asp:ListItem>
<asp:ListItem Value="0,7"></asp:ListItem>
<asp:ListItem Value="1"></asp:ListItem>
</asp:RadioButtonList>
</td>
<td>
<asp:RadioButtonList ID="RadioButtonList4" runat="server" Height="23px" RepeatDirection="Horizontal" Width="383px">
<asp:ListItem Value="0,6"></asp:ListItem>
<asp:ListItem Value="0,7"></asp:ListItem>
<asp:ListItem Value="0,8"></asp:ListItem>
<asp:ListItem Value="0,9"></asp:ListItem>
<asp:ListItem Value="1"></asp:ListItem>
</asp:RadioButtonList>
</td>
<td>
<asp:TextBox ID="TextBox2" runat="server" Width="63px"></asp:TextBox>
</td>
</tr>
<tr>
<td style="width: 73px">
</td>
<td style="width: 145px">
</td>
<td>
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td style="width:73px"> </td>
<td style="width:145px"> </td>
<td> </td>
<td style="text-align:right">TOTAL FIELD:</td>
<td>
<asp:TextBox ID="TextBox3" runat="server" Width="63px"></asp:TextBox>
</td>
</tr>
</table>
答案 0 :(得分:0)
您需要发布数据,有很多方法。
example.aspx
设置autopostback属性
<asp:RadioButtonList ID="RadioButtonList2" runat="server" Height="23px"
RepeatDirection="Horizontal" Width="383px" AutoPostBack="True">
<asp:ListItem Value="0,6"></asp:ListItem>
<asp:ListItem Value="0,7"></asp:ListItem>
<asp:ListItem Value="0,8"></asp:ListItem>
<asp:ListItem Value="0,9"></asp:ListItem>
<asp:ListItem Value="1"></asp:ListItem>
</asp:RadioButtonList>
<asp:RadioButtonList ID="RadioButtonList4" runat="server" Height="23px"
RepeatDirection="Horizontal" Width="383px" AutoPostBack="True">
<asp:ListItem Value="0,6"></asp:ListItem>
<asp:ListItem Value="0,7"></asp:ListItem>
<asp:ListItem Value="0,8"></asp:ListItem>
<asp:ListItem Value="0,9"></asp:ListItem>
<asp:ListItem Value="1"></asp:ListItem>
</asp:RadioButtonList>
example.cs
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
}
else {
UpdateTotals();
}
}
protected void UpdateTotals()
{
decimal multiply=0m;
decimal multiply2=0m;
//you have to check the value
if (DropDownList1.SelectedValue != "Select" && RadioButtonList1.SelectedValue != "" && RadioButtonList2.SelectedValue != "")
{
multiply = Decimal.Parse(DropDownList1.SelectedValue) * Decimal.Parse(RadioButtonList1.SelectedValue) * Decimal.Parse(RadioButtonList2.SelectedValue);
TextBox1.Text = multiply.ToString();
}
if (DropDownList2.SelectedValue != "Select" && RadioButtonList3.SelectedValue != "" && RadioButtonList4.SelectedValue != "")
{
multiply2 = Decimal.Parse(DropDownList2.SelectedValue) * Decimal.Parse(RadioButtonList3.SelectedValue) * Decimal.Parse(RadioButtonList4.SelectedValue);
TextBox2.Text = multiply2.ToString();
}
TextBox3.Text = string.Format("{0}", multiply + multiply2);
}