简体   繁体   English

DropDownList:SelectedIndexChanged不触发

[英]DropDownList: SelectedIndexChanged do not fire

I fill a ASP Dropdownlist in the pageload 我在页面加载中填写了一个ASP Dropdownlist

protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {           
                for (int i = 0; i < _maxStationsAnz; i++)
                {
                    String stations = arrayList[1];

                    _allData = stations.Split(Convert.ToChar("/"));
                    _data = _allData[i].Split(Convert.ToChar(";"));

                    ddWeatherstations.Items.Add(_data[0]);
                }
        }

When a new station is selected, it should update informations. 选择新电台后,它应更新信息。 I use the OnSelectedIndexChanged attribute on my aspx site. 我在aspx网站上使用OnSelectedIndexChanged属性。

My code behind: 我后面的代码:

protected void ddWeatherstations_SelectedIndexChanged(object sender, EventArgs e)
    {
        for (int i = 0; i < _maxStationsAnz; i++)
        {
            if (ddWeatherstations.SelectedIndex == i)
            {
                  lselected.Text = "Index changed!";
                  //unimportant code
                  //....
            }
        }
    }

When I set a breakpoint and run the program and change the value of the dropdownlist, nothing happens. 当我设置一个断点并运行程序并更改下拉列表的值时,什么也没有发生。

You need to set AutoPostBack property of your dropdownlist ddWeatherstations to True . 您需要将下拉列表ddWeatherstations AutoPostBack属性设置为True

Try This: 尝试这个:

<asp:DropDownList ID="ddWeatherstations" runat="server" AutoPostBack="true" 
    OnSelectedIndexChanged="ddWeatherstations_SelectedIndexChanged">
</asp:DropDownList>

您需要设置属性AutoPostBack="true"但是每次您选择DropDownList的其他索引时,这都会回发所有页面,因此我建议您将DropDownList放入AJAX更新面板中。

暂无
暂无

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

相关问题 在Repeater控件中DropDownList,无法触发SelectedIndexChanged - DropDownList in Repeater control, can't fire SelectedIndexChanged 为什么DropDownList.SelectedIndexChanged事件不会触发? - Why DropDownList.SelectedIndexChanged event does not fire? 如果已在下拉列表中选择了 Item,则不会触发 SelectedIndexChanged 事件? - SelectedIndexChanged event does not fire if Item is already selected in a dropdownlist? dropdownlist中的First Item根本不会触发SelectedIndexChanged - First Item in dropdownlist doesn't fire SelectedIndexChanged at all asp.net dropdownlist的第一个选择不会触发SelectedIndexChanged事件 - asp.net dropdownlist first selection does not fire SelectedIndexChanged event 在C#中使用Databind,DropDownList不会在SelectedIndexChanged上触发事件 - DropDownList doesn't Fire Event on SelectedIndexChanged Using Databind in C# 在后面的C#代码中选择索引时,不会触发DropDownList.SelectedIndexChanged - DropDownList.SelectedIndexChanged does not fire when selecting index in C# code behind 将我的 ASP.NET 应用程序移动到 Windows 2008 服务器,现在 DropDownList SelectedIndexChanged 事件不会触发 - Moved my ASP.NET app to a Windows 2008 server, now DropDownList SelectedIndexChanged events don't fire 与下拉列表的selectedindexchanged有关 - Concerned with selectedindexchanged of dropdownlist 下拉列表 selectedindexchanged 事件未触发 - Dropdownlist selectedindexchanged event is not firing
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM