简体   繁体   English

SelectedIndexChanged事件未在数据列表的页脚内触发

[英]SelectedIndexChanged event not firing inside the footer of a Datalist

I´ve been searching the web and Stackoverflow for this answer, I´ve tried some but with no success. 我一直在网上和Stackoverflow上寻找这个答案,我尝试了一些但没有成功。 My problem: I have a dropdownlist inside the footer of a Datalist. 我的问题:我在数据列表的页脚中有一个下拉列表。 My page´s AutoEventWireup is set to true. 我页面的AutoEventWireup设置为true。 My Dropdown´s autopostback is set to true. 我的Dropdown的自动回传设置为true。 I bind the event on itemcreation of the datalist. 我将事件绑定到数据列表的itemcreation上。 The dropdown does get the postback but doesn´t call the function set at the SelectedIndexChanged event. 下拉列表确实会获得回发,但不会调用SelectedIndexChanged事件中设置的函数。

On create: 创建时:

protected void dlCartItemsMonetary_ItemCreated(object sender, DataListItemEventArgs e)
{
    if (e.Item.ItemType == ListItemType.Footer)
    {
        DropDownList combo = (DropDownList)e.Item.FindControl("ddlDeliveryService");
        if (combo != null)
        {
            combo.SelectedIndexChanged += new EventHandler(ddlDeliveryService_SelectedIndexChanged);
        }
    }
}

The dropdown: 下拉列表:

<asp:DropDownList ID="ddlDeliveryService" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlDeliveryService_SelectedIndexChanged" EnableViewState="true">

It does the postback but it doesn´t enter the ddlDeliveryService_SelectedIndexChanged function. 它执行回发,但不输入ddlDeliveryService_SelectedIndexChanged函数。

Can anyone give me some tips on how to solve it? 谁能给我一些解决方法的提示?

Thanks in advance 提前致谢

Resolved! 解决!

My problem and many other's is that I was setting the DataSource and DataBinding the DataList on every postback. 我的问题以及其他许多问题是,我在每次回发时都设置了DataSource和DataBinding DataList。 As soon as I added the postback validation the event begin to fire. 一旦添加回发验证,该事件就会开始触发。 Code below: 代码如下:

    if (this.Page.IsPostBack == false)
    {
        dlCartItemsMonetary.DataSource = list;
        dlCartItemsMonetary.DataBind();
    }

If you are having the same problem with events not firing check your code for the same issue! 如果您遇到事件无法触发的相同问题,请检查您的代码是否存在相同问题!

Thanks jpartjh for your comment, it made me think about the lifecycle of the page. 感谢jpartjh的评论,这让我思考了页面的生命周期。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM