我使用下拉列表,允许用户选择一个值(代表一个客户端名称。)我在Page_Load中绑定该列表,就像这样:
if(!IsPostBack)
{
var airClients = (from ac in db.AIR_CLIENTS orderby ac.CLIENT select ac.CLIENT).ToList();
ddlClients.DataSource = airClients;
ddlClients.DataBind();
}
如果我到达我的编辑视图(填写了所有字段,包括该下拉列表),我可以通过在列表中选择另一个来更改客户端。但是,当我保存时,不会考虑新选择的值。我试图这样做:
protected void btnSave_Click(object sender, EventArgs e)
{
Entities db = new Entities();
if (Session["id"] != null)
{
int id = Convert.ToInt32(Session["id"].ToString());
SIMULATION simulation = (from s in db.SIMULATION where s.SIMULATION_ID == id select s).FirstOrDefault();
string client = ddlClients.SelectedItem.Text;
AIR_CLIENTS currentClient = (from ac in db.AIR_CLIENTS where ac.CLIENT == client select ac).FirstOrDefault();
int monthNego = Convert.ToInt32(ddlMonthNegotiation.SelectedItem.Text);
int roundNego = Convert.ToInt32(ddlRoundNegotiation.SelectedItem.Text);
simulation.SIMULATION_NAME = mmDesc.Text;
simulation.SIMULATION_TYPE = ddlSimulationType.SelectedItem.Text;
simulation.CLIENT_ID = currentClient.CLIENT_ID;
simulation.SIM_START_DATE = dteStart.Date;
simulation.SIM_END_DATE = dteEnd.Date;
simulation.CONTRACT_YEAR = ddlContractYear.SelectedItem.Text;
simulation.MONTH_OF_NEGOTIATION = monthNego;
simulation.ROUND_OF_NEGOTIATION = roundNego;
db.SaveChanges();
Response.Redirect("MainPage.aspx");
}
}
因此,为了清楚地了解我想说的话,如果在我的编辑视图中,我已经得到了#34; Apple"作为原始值,我想通过选择"亚马逊"来改变它,当我调试时,我仍然看到" Apple"作为选定的值。
我无法弄清楚我应该在哪里修复代码以使其正常工作。有什么想法吗?
编辑:ASPX下拉列表代码
<dx:ASPxComboBox runat="server" ID="ddlClients" ClientInstanceName="ddlClients"></dx:ASPxComboBox>
我使用的是DevExpress库,但我认为它不可靠。