在下面的代码中,我希望在文本框Invoiceno中插入一个对应于下拉菜单TotalAmount的值。另外,如果下拉菜单ChequeNumber的值是支票,我希望启用文本框PaymentMode。但是,只有在我按下提交按钮之后,这些值才会出现在文本框中。我做错什么了?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace OrderManagementSystem
{
public partial class MakePayment : System.Web.UI.Page
{
Dictionary<int, int> InvoiceAmount = new Dictionary<int, int>();
protected void Page_Load(object sender, EventArgs e)
{
ChequeNumber.Enabled = false;
}
protected void InvoiceNo_SelectedIndexChanged(object sender, EventArgs e)
{
InvoiceAmount.Add(1111, 100000);
InvoiceAmount.Add(2222, 200000);
InvoiceAmount.Add(3333, 300000);
InvoiceAmount.Add(4444, 400000);
int InvoiceValue = Convert.ToInt32(InvoiceNo.SelectedValue);
foreach (KeyValuePair<int, int> item in InvoiceAmount)
{
if (InvoiceValue == item.Key)
{
TotalAmount.Text = Convert.ToString(item.Value);
}
}
}
protected void PaymentMode_SelectedIndexChanged(object sender, EventArgs e)
{
if (PaymentMode.SelectedValue == "Cheque")
{
ChequeNumber.Enabled = true;
if (ChequeNumber.Text=="")
{
}
}
}
protected void TotalAmount_TextChanged(object sender, EventArgs e)
{
}
}
}发布于 2014-08-23 18:33:14
在AutoPostBack=声明中添加DropDowlList“true”。当值被更改时,这将使页面发布到服务器。您可以考虑添加UpdatePanel以通过AJAX进行回发。
发布于 2014-08-25 12:07:05
1>在DropDownList的.aspx页面中添加AutoPostBack="true“。
2>第二个问题在于页面加载函数
protected void Page_Load(object sender, EventArgs e)
{
ChequeNumber.Enabled = false;
}每次加载页面时都禁用文本框ChequeNumber。要解决此问题,需要将ChequeNumber状态保持在ViewState["xyz"]中。
https://stackoverflow.com/questions/25464829
复制相似问题