0

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?

V4Vendetta
  • 37,194
  • 9
  • 78
  • 82
sun
  • 85
  • 1
  • 4
  • 15

1 Answers1

2

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.

Kishore Kumar
  • 12,675
  • 27
  • 97
  • 154
  • @kishorejangid...let me try it – sun Dec 30 '11 at 09:42
  • Its better to encapsulate the code within the indexchange as a method and call the method explicitly. IMO Event handlers should only be invoked as a consequence of an event. [Check burned finger](http://stackoverflow.com/a/6545857/570150) – V4Vendetta Dec 30 '11 at 09:43