在程式中動態產生DropDownList的選項內容, 其實很容易做到.

只要建立一個DropDownList的Instance, 然後使用Add或Insert方法, 把ListItem加進去就可以了, 就像:

DropDownList dl = new DropDownList();
dl.CssClass 
= "Normal";
dl.ID 
= dropDownListId;
dl.AutoPostBack 
= false;
dl.Items.Clear();
dl.Items.Add(
new ListItem(Text, Data ));

但要注意的是, 如果在產生的過程中, 使用了SelectedValue, 那麼DropDownList的SelectedIndex就會被設定. 不光是指定它的值, 就是顯示它的值出來看也會有同樣的問題.