asp.net下拉列表SelectedIndexChanged不起作用

时间:2017-01-09 08:10:47

标签: c#

我有两个功能:

  1. 创建下拉列表
  2. 它的事件处理程序(试图重定向......只是为了知道它正在工作)。
  3. 但它不起作用.. 请帮助:(

    创建下拉列表:

    DropDownList createUsersDropDownList(ShiftClass shift, string selectedDate,int dayNumber)//creating the drop down list of users of shift
    {
        DropDownList output=new DropDownList();
        output.Items.Add(new ListItem("","0"));
        List<UserClass> listOfUsers = new List<UserClass>();
        //arrange.watchersRoles = list of roles can watch
        DateTime theDate = DateTime.Parse(selectedDate);
        DBConnect dbConn = new DBConnect();
        using (dbConn.conn)
        {
            SqlCommand sqlGetUserDetails;
            SqlDataReader rsGetUserDetails;
            foreach (int allowedRole in arrange.watchersRoles)//for every role, create userclass
            {
                sqlGetUserDetails= new SqlCommand("select ID from dbo.Users where roleID=" + allowedRole, dbConn.conn);//calling the allowed users with id
                rsGetUserDetails = sqlGetUserDetails.ExecuteReader();
                if (rsGetUserDetails.HasRows)
                    while(rsGetUserDetails.Read())  //get the details from db
                        listOfUsers.Add(new UserClass((int)rsGetUserDetails["ID"]));//adding the user to the list
                rsGetUserDetails.Close();
            }//end foreach role
            dbConn.conn.Close();
        }//end using conn
    
        ListItem userToAdd;
    
        foreach (UserClass allowedUser in listOfUsers)//foreach user, add him to the drop down list
        { 
    
            userToAdd=new ListItem();
            UserClass currentUserInShift = shift.userInShift(shift.shiftID, dateToSql(theDate.AddDays(0).Date));
            if(currentUserInShift!= null )//there is user in this shift
                if (allowedUser.userData.id == currentUserInShift.userData.id)//user is equal ==>  selected
                    userToAdd.Selected = true;
            userToAdd.Value=allowedUser.userData.id.ToString();
            userToAdd.Text=allowedUser.userData.firstName + " " + allowedUser.userData.lastName;
            output.Items.Add(userToAdd);
    
        }
    
        output.ID = theDate.AddDays(0).Date + "_" + shift.shiftID.ToString();
        output.SelectedIndexChanged += new EventHandler(updateUserInShift);
        output.EnableViewState = true;
        output.AutoPostBack = true;
    
        return output;
    }//end createDropDownList
    

    事件处理程序:

    protected void updateUserInShift(object sender, EventArgs e)
    {
        string originalShift;
        string date;
        int userID;
    
        DropDownList selectedList = (DropDownList)sender;
    
        originalShift = selectedList.ID;
        Page.Response.Redirect("http://www.google.com", true);
    }
    

    **但没有任何反应......有一个回复但没有事件处理程序.. **

0 个答案:

没有答案