在我的 ASP.NET 项目中。我有两个下拉列表和一个复选框。选中复选框时, 的选定值DropDownList1
必须与 的选定值相同DropDownList2
。但DropDownList1.SelectedValue
它不起作用。
这是我的代码:
protected void chkSameBAddress_CheckedChanged(object sender, EventArgs e)
{
try
{
if (this.chkSameBAddress.Checked == true)
{
this.txtcSAddress1.Text= this.txtcBAddress1.Text;
this.txtcSAddress2.Text = this.txtcBAddress2.Text;
this.txtcSAddress3.Text = this.txtcBAddress3.Text;
this.txtcSAddress4.Text = this.txtcBAddress4.Text;
this.txtcSCity.Text = this.txtcBCity.Text;
this.txtcSPostCode.Text = this.txtcBPostCode.Text;
this.txtcSState.Text = this.txtcBState.Text;
this.ddlcSCountry.Items.FindByValue(ddlcBCountry.SelectedItem.Value).Selected = true;
}
}
catch (Exception ex)
{
logger.Error(ex.Message);
throw;
}
}
如上例所示,如果选中chkSmaeBAddress ,则ddlcSCountry的选定值必须与ddlcBCountry选定的值相同。