【问题标题】:About SelectedIndex property in a DropDownList关于 DropDownList 中的 SelectedIndex 属性
【发布时间】:2012-01-20 10:05:39
【问题描述】:

抱歉我的无知,但我一直认为将DropDownListSelectedIndex 属性设置为SelectedIndexChanged 事件会被触发...我错了吗?

在文档中搜索我没有发现任何明确的...

谢谢

【问题讨论】:

  • 如果你得到了你想要的信息,别忘了将答案标记为已接受

标签: c# asp.net .net events drop-down-menu


【解决方案1】:

不,它不能触发 selectionchange 事件。

如果您以编程方式进行设置,则不会触发 selectionchange 事件。

【讨论】:

    【解决方案2】:

    DropDownlist Class Selected Index Changed Event 当列表控件的选择在发送到服务器的帖子之间发生变化时触发。 请确保关注以触发事件。

    1. AutoPostBack="true" How to use DropDownList AutoPostBack feature
    2. onselectedindexchanged="处理程序名称"

    下面是代码。

    <asp:DropDownList ID="ddl1" runat="server" AutoPostBack="true"
    onselectedindexchanged="ddl1_SelectedIndexChanged">
       <asp:ListItem Text ="1" Value="1"></asp:ListItem>
       <asp:ListItem Text ="2" Value="2"></asp:ListItem>
    </asp:DropDownList>
    
    
    protected void ddl1_SelectedIndexChanged(object sender, EventArgs e)
    {
    
    }
    

    注意 - 在运行时设置索引永远不会触发事件。

    请同时浏览以下链接。

    How to: Respond to Changes in List Web Server Controls

    How to use DropDownList AutoPostBack feature

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-05
      相关资源
      最近更新 更多