我在更新面板中有一個DDL,並且我無法獲取SelectedItemChanged方法以在將數據綁定到它時觸發。在Page_Load中,我有:dropdownlist不會觸發SelectedItemChanged
ddl.DataSource = GetList();
ddl.DataBind();
GetList()
返回List<string>
值都在那裏,但是當我選擇一個沒有任何反應。
如果我要手動把它們像這樣:
ddl.Items.Add("1");
ddl.Items.Add("2");
ddl.Items.Add("3");
它的工作原理,爲什麼呢?
如果我綁定數據,則永遠不會輸入以下方法。
protected void ddl_SelectedIndexChanged(object sender, EventArgs e)
{
string test = ddl.SelectedItem.Text;
}
<asp:DropDownList runat="server" ID="ddl" Width="150px"
OnSelectedIndexChanged="ddl_SelectedIndexChanged"></asp:DropDownList>
重複的問題:http://stackoverflow.com/questions/70109/dropdownlist-doesnt-postback-on-selectedindexchanged ...只需將'AutoPostBack =「true」'添加到您的DropDownList定義。 – daniloquio 2012-07-19 16:03:25