简体   繁体   中英

SelectedIndexChanged() event of a dropdownlist on a checkbobx checking

I have a checkbox to indicate that communication address is same as the permanent address. There are 4 dropdownlists -

  1. DRP_Comm_Country1
  2. DRP_Comm_State1
  3. DRP_Per_Country2
  4. DRP_Per_State2

When i check the checkbox, the items of permanent address dropdownlists should be same as that of communication address dropdownlists.How to make it possible?

My code is

protected void CheckBox2_CheckedChanged(object sender, EventArgs e)
{
    DRP_Per_Country2.SelectedIndex = DRP_Comm_Country1.SelectedIndex;
}

But the SelectedIndexChanged( ) Event of DRP_Per_Country2 is not get fired.Is it a wrong method? If so ,how to work it?

First of all, you have to set the

AutoPostBack = true

property for all the DropDownList . If this wont work then call the SelectedIndexChanged Event manually

protected void CheckBox2_CheckedChanged(object sender, EventArgs e)
{
    DRP_Per_Country2.SelectedIndex = DRP_Comm_Country1.SelectedIndex;
    DRP_Per_Country2_SelectedIndexChanged(sender,e);
}

This will surely fire the event.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM