c# - Repeater 控件中的 DropDownList,无法触发 SelectedIndexChanged

标签 c# asp.net

我有一个转发器控件,在页脚中有一个 DropDownList。在我的代码隐藏中,我有:

protected void ddMyRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    if (e.Item.ItemType == ListItemType.Item
            || e.Item.ItemType == ListItemType.AlternatingItem)
    {
       // Item binding code
    }

    else if (e.Item.ItemType == ListItemType.Footer)
    {
        DropDownList ddl = e.Item.FindDropDownList("ddMyDropDownList");
        // Fill the list control
        ddl.SelectedIndexChanged += new  
           EventHandler(ddMyDropDownList_SelectedIndexChanged);
        ddl.AutoPostBack = true;
    }
 }

该页面出现在 PostBack 中,但是我的 EventHandler 没有被调用。有什么想法吗?

最佳答案

如果您只想触发 OnSelectedIndexChanged,它应该是这样的:

Page.aspx - 源代码

<FooterTemplate>
    <asp:DropDownList ID="ddlOptions"
             runat="server" 
             AutoPostBack="true" 
             onselectedindexchanged="ddlOptions_SelectedIndexChanged">
        <asp:ListItem>Option1</asp:ListItem>
        <asp:ListItem>Option2</asp:ListItem>
    </asp:DropDownList>
</FooterTemplate>

Page.aspx.cs - 代码隐藏

protected void ddlOptions_SelectedIndexChanged(object sender, EventArgs e)
    {
        //Event Code here.
    }

就是这样。不需要更多。

关于c# - Repeater 控件中的 DropDownList,无法触发 SelectedIndexChanged,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/175845/

相关文章:

asp.net - 如何在 Ext.NET 窗口中放置 GridPanel?

c# - 在 ASP.NET 页面上显示计算机信息

javascript - 如何将序列化的多维数组从 C# 传递到 Javascript

c# - 防止出现未处理的异常对话框

c# - 将包含未知大小的 int 数组的结构从 c# 传递到 c 并返回

C# 遍历 NameValueCollection

asp.net - 渲染文件夹中的所有部分 View

c# - 登录时存储用户然后按需推送数据

c# - 如何防止编辑器弹出窗口关闭?

c# - EventTrigger 中的模板绑定(bind)