Help: DropDownList's selectedIndexChanged???

Hi,
I have a form with a drop-down-list and a button.
I want an action to be trigged as soon as I select a new item on the dropdown list.

The code below does not show the message, but if I move the code in drop_SelectedIndexChanged method into btnSave_Click method it works perfectly.

I have used DropDownList's SelectedIndexChanged.

The action only takes place when I click on the button.

Here is the brief code:


protected System.Web.UI.WebControls.Button btnSave;
protected System.Web.UI.WebControls.DropDownList drop;
protected System.Web.UI.WebControls.Label lblMessage;


private void Page_Load(object sender, System.EventArgs e)
{
DataBind();
}


private void btnSave_Click(object sender, System.EventArgs e)
{

}

private void drop_SelectedIndexChanged(object sender, System.EventArgs e)
{
lblMessage.Text = "Selected item changed";
lblMessage.Visible = true;
}



private void InitializeComponent()
{

btnSave.Click += new System.EventHandler(this.btnSave_Click);
drop.SelectedIndexChanged += new System.EventHandler(this.drop_SelectedIndexChanged);
this.Load += new System.EventHandler(this.Page_Load);

}You have to set your ddl to autopostback = true...

if it is false, it will not fire the selectionIndexChange event..

- Tak
 
Back
Top