我正在使用Asp.net c#创建一个简单的患者计费程序。现在,我有一个带有“Ward”,“Semi Private”和“Private”项目的下拉列表如果用户选择下面的文本框,它将自动为700,如果半私有它应该是1000,如果私有它应该是2000。我下面还有一个文本框,表明患者住了多少天,用户是应该输入日期的人,例如他来自病房,他住的日数是3,那么计算应该是700 * 3。我还有一个显示答案的文本框。我希望你们理解我上面解释过的事情。到目前为止,这是我的代码:
Default.aspx的
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
if (DropDownList1.Text == "Ward")
{
TextBox4.Text = "700";
}
if (DropDownList1.Text == "Semi Private")
{
TextBox4.Text = "1000";
}
if (DropDownList1.Text == "Private")
{
TextBox4.Text = "2000";
}
}
protected void Button1_Click(object sender, EventArgs e)
{
}
}
答案 0 :(得分:0)
首先在你的asp标签中为下拉列表添加一个属性,如 -
<asp:DropDownList ID="DropDownList1" runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" AutoPostBack="true">
然后在事件中,编写以下代码 -
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
string selected = DropDownList1.SelectedItem.ToString();
if(selected == "Ward")
{
int NetAmount = 700 * 3; //you can use any int variable in place of "3" as well
TextBox1.Text = NetAmount.ToString();
}
else if(selected == "Semi Ward")
{
TextBox1.Text = "1000";
}
else
{
TextBox1.Text = "2000"
}
}
就是这样。希望它会有所帮助。