我使用多個項目填充下拉列表。當用戶選擇其中一個項目時,會填充第二個下拉列表。Items.Clear()後更新下拉列表()
當用戶點擊第一個下拉列表中的「x」按鈕時,必須清除兩個下拉列表。第一個下拉列表會自動清除,並使用「dropdown.Items.Clear()」清除第二個下拉列表。
碰巧,當我再次加載第一個下拉列表中的數據時,第二個下拉列表不會更新。
這是代碼:
protected void DropDownDiagStati_SelectedIndexChanged(object sender, EventArgs e)
{
int selectedIndex = this.DropDownDiagStati.SelectedIndex;
PopulateDDLStates(selectedIndex);
}
private void PopulateDDLStates(int selectedIndex)
{
// Ottengo i diagrammi di stato in sessione
ArrayList diagrammiStato = Session["stateDiagrams"] as ArrayList;
if(selectedIndex > 0)
{
// Ottengo il diagramma di stato selezionato
DocsPaWR.DiagrammaStato currDiagStato = (DocsPaWR.DiagrammaStato)diagrammiStato[selectedIndex - 1];
// Ottengo gli stati del diagramma di stato selezionato
Stato[] stati = currDiagStato.STATI;
for(int i = 0; i < stati.Length; i++)
{
ListItem item = new ListItem();
item.Value = Convert.ToString(stati[i].SYSTEM_ID);
item.Text = stati[i].DESCRIZIONE;
this.DropDownStati.Items.Add(item);
this.UpPanelStatiDdl.Update();
}
}
else
{
this.DropDownStati.Items.Clear();
this.UpPanelStatiDdl.Update();
}
}
我只看到在第二個下拉舊的價值,我無法選擇它。
您是否將autopostback設置爲true? –
在第一個下拉列表中,是的,因爲它具有OnSelect ..監聽器。 – user3075478