关于DropDownList中的SelectedIndex属性

时间:2012-01-20 10:05:39

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

对不起我的无知,但我一直认为设置SelectedIndex DropDownList事件的SelectedIndexChanged属性会被解雇......我错了吗?

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

由于

2 个答案:

答案 0 :(得分:2)

不,它无法触发selectionchange事件。

如果您以编程方式设置而不是触发selectionchange事件。

答案 1 :(得分:0)

当列表控件中的选择在发布到服务器的帖子之间发生更改时,

DropDownlist Class Selected Index Changed Event将触发。 请确保关注以下事件。

  1. AutoPostBack =“true”How to use DropDownList AutoPostBack feature
  2. onselectedindexchanged =“处理程序的名称”
  3. 以下是代码。

    <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