In my ASP.NET project. I have two dropdownlist and a checkbox. When the checkbox is checked, the selected value of DropDownList1
must be same as selcted value of the DropDownList2
. But the DropDownList1.SelectedValue
is not working.
Here is my code:
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;
}
}
As seen in the example above, if chkSmaeBAddress is checked then the selected value of ddlcSCountry must be same as ddlcBCountry selected value.