在C#代码后面选择索引时,不会触发DropDownList.SelectedIndexChanged

时间:2012-10-06 14:29:53

标签: c# asp.net

我试图在C#代码后面的DropDownList中选择索引但是不会触发SelectedIndexChanged事件。什么是正确的方法?

  DropDownListChapterTitles.SelectedIndex = 1;


  protected void DropDownListChapterTitles_SelectedIndexChanged(object sender, EventArgs e)
  { }

2 个答案:

答案 0 :(得分:0)

DropDownListChapterTitles.SelectedIndex = 1;
// Call it yourself
DropDownListChapterTitles_SelectedIndexChanged(this, null);

答案 1 :(得分:0)

检查你的标记应该是这样的

<asp:DropDownList runat="server" ID="DropDownListChapterTitles" AutoPostBack="True"
     OnSelectedIndexChange="DropDownListChapterTitles_SelectedIndexChanged">

</asp:DropDownList>

我添加了OnSelectedIndexChange="DropDownListChapterTitles_SelectedIndexChanged"