简体   繁体   中英

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. 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. 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.

Edit2: Here is the code several people have asked for.

<%@ 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

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

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

ddlPojects.SelectedIndexChanged += new EventHandler(ddlPojects_SelectedIndexChanged);

Your code behind and the .aspx code looks fine. What I suspect is a namespace issue.

Can you post up your page directive (this bit in your aspx page <%@ 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.

Have you also tried adding a break point in the ddlProjects_SelectedIndexChanged to see if it get hit?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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