M
Matt C.
I have a dropdown list (ddlReportees) that autopostsback and populates a
listbox (lstEvalHistory). In the event handler for the ddl
SelectedIndexChanged, the top item in lstEvalHistory is selected (see
(1)).
I expected setting lstEvalHistory.SelectedIndex = 0 to fire
SelectedIndexChanged for lstEvalHistory. But it doesn't.
It is no big deal to add a bit of code to get the same effect (2). But
my mental model is off. Can anyone tell me why setting SelectedIndex in
code does not cause SelectedIndexChanged to fire?
Code is below.
Thanks,
Matt
protected void ddlReportees_SelectedIndexChanged(object sender,
EventArgs e)
{
string sEmpl = this.ddlReportees.SelectedValue;
int iEmplID = int.Parse(sEmpl.Substring(2));
this.GetAndDisplayEvaluations(iEmplID);
if (this.lstEvalHistory.Items.Count > 0)
{
this.lstEvalHistory.SelectedIndex = 0; // (1) (why no event?)
this.DisplayEvalText(); // (2) (workaround)
}
else
this.DisplayEmptyEvalTable();
this.ddlReportees.Focus();
}
protected void lstEvalHistory_SelectedIndexChanged(object sender,
EventArgs e)
{
DisplayEvalText();
}
listbox (lstEvalHistory). In the event handler for the ddl
SelectedIndexChanged, the top item in lstEvalHistory is selected (see
(1)).
I expected setting lstEvalHistory.SelectedIndex = 0 to fire
SelectedIndexChanged for lstEvalHistory. But it doesn't.
It is no big deal to add a bit of code to get the same effect (2). But
my mental model is off. Can anyone tell me why setting SelectedIndex in
code does not cause SelectedIndexChanged to fire?
Code is below.
Thanks,
Matt
protected void ddlReportees_SelectedIndexChanged(object sender,
EventArgs e)
{
string sEmpl = this.ddlReportees.SelectedValue;
int iEmplID = int.Parse(sEmpl.Substring(2));
this.GetAndDisplayEvaluations(iEmplID);
if (this.lstEvalHistory.Items.Count > 0)
{
this.lstEvalHistory.SelectedIndex = 0; // (1) (why no event?)
this.DisplayEvalText(); // (2) (workaround)
}
else
this.DisplayEmptyEvalTable();
this.ddlReportees.Focus();
}
protected void lstEvalHistory_SelectedIndexChanged(object sender,
EventArgs e)
{
DisplayEvalText();
}