简体   繁体   English

SelectedIndexChanged事件在任何情况下均不会触发

[英]SelectedIndexChanged Event not firing under any circumstances

As the title says I am experiencing a problem where the SelectedIndexChanged Event of a drop down list will not fire under any circumstances. 如标题所述,我遇到一个问题,在任何情况下下拉列表的SelectedIndexChanged事件都不会触发。 I have spent several hours looking for the solution and trying different things. 我已经花了几个小时寻找解决方案,并尝试了不同的方法。 Some places suggest that this is a known bug and provide work-arounds but none of them have worked for me up until this point. 有些地方表明这是一个已知的错误,并且提供了解决方法,但是到目前为止,它们都没有对我有用。

The drop down in question is built here: 有问题的下拉列表在此处构建:

<tr>
  <td>
    Select Project
  </td>
  <td>
    <asp:DropDownList ID="ddlProjects" runat="server" 
      OnSelectedIndexChanged="ddlProjects_SelectedIndexChanged" AutoPostBack="true">
    </asp:DropDownList>
  </td>
</tr>  

This seems standard enough to me so I do not know where it could be going wrong. 这对我来说似乎已经足够标准了,所以我不知道它可能出问题了。

EDIT (sorry I am new to this): 编辑(对不起,我是新来的):

Code Behind: 背后的代码:

protected void ddlProjects_SelectedIndexChanged(object sender, EventArgs e)
    {
        List<DashBoardImport> selectedProject = DBI.GetProject(Convert.ToInt32(ddlProjects.SelectedValue));
        foreach (var proj in selectedProject)
        {
            txtProjectName.Text = proj.ProjectName;
            this.ddlStatus.SelectedIndex = proj.Status.Equals("Current") ? 0 : 1;
            var priority = proj.Priority.PriorityName;
            if (priority.Equals("Low"))
            {
                ddlPriority.SelectedIndex = 0;
            }
            else if (priority.Equals("Medium"))
            {
                ddlPriority.SelectedIndex = 1;
            }
            else if (priority.Equals("High"))
            {
                ddlPriority.SelectedIndex = 2;
            }
            //txtRank.Text = proj.ProjectRank.ToString();
            txtBusinessArea.Text = proj.BusinessArea.BusinessAreaName;
            txtRequester.Text = proj.Requestor;
        }
        //selectedIndex.Value = ddlProjects.SelectedIndex.ToString();
    }  

There is no javascript even touching this function in anyway. 无论如何,甚至没有JavaScript可以触摸此功能。 I have removed it to try and take things back to basics so to speak. 可以这么说,我已经删除了它,以尝试使事情回到基础。 I have put break points in the page_load in the onselectedindexchanged function and in several other places and the event is never fired and the selected index is never changed from 0. 我在onselectedindexchanged函数和其他几个地方的page_load中放置了断点,并且从未触发该事件,并且所选索引从未从0更改。

Edit2: Here is the code several people have asked for. Edit2:这是几个人要求的代码。

<%@ Page Title="Future Projects" Language="C#" MasterPageFile="~/Site.Master" EnableEventValidation="true"
AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="ITDashBoard.Web.Default" %>

Add AutoEventWireup="true" to your page in given below line like this 在下面的行中将AutoEventWireup="true"添加到您的页面,如下所示

<%@ Page Language="C#" AutoEventWireup="true"  .................. %>

Edited: then add your own event handler 编辑:然后添加您自己的事件处理程序

ddlPojects.SelectedIndexChanged += new EventHandler(ddlPojects_SelectedIndexChanged);

Your code behind and the .aspx code looks fine. 您的代码后面以及.aspx代码看起来不错。 What I suspect is a namespace issue. 我怀疑是名称空间问题。

Can you post up your page directive (this bit in your aspx page <%@ Page Language="C#" ..... ). 您是否可以发布页面指令(aspx页面<%@ Page Language="C#" .....此位)。 Specifically I want to see the inherits attribute. 具体来说,我想查看继承属性。 I also need to the the namespace of the .cs class where protected void ddlProjects_SelectedIndexChanged(object sender, EventArgs e) resides. 我还需要.cs类的命名空间,其中protected void ddlProjects_SelectedIndexChanged(object sender, EventArgs e)驻留在该命名空间中。

Have you also tried adding a break point in the ddlProjects_SelectedIndexChanged to see if it get hit? 您是否还尝试过在ddlProjects_SelectedIndexChanged中添加断点以查看是否被击中?

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

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