0

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" %>
4

2 回答 2

0

您的代码和 .aspx 代码看起来不错。我怀疑是命名空间问题。

你可以发布你的页面指令(这个位在你的 aspx 页面中<%@ Page Language="C#" .....)。具体来说,我想查看继承属性。我还需要 .cs 类所在的命名空间protected void ddlProjects_SelectedIndexChanged(object sender, EventArgs e)

您是否还尝试在 ddlProjects_SelectedIndexChanged 中添加断点以查看它是否被命中?

于 2013-06-05T15:52:18.687 回答
0

像这样在下面给出的行中添加AutoEventWireup="true"到您的页面

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

编辑: 然后添加您自己的事件处理程序

ddlPojects.SelectedIndexChanged += new EventHandler(ddlPojects_SelectedIndexChanged);
于 2013-06-05T15:35:58.883 回答