我有两个功能:
但它不起作用.. 请帮助:(
创建下拉列表:
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);
}
**但没有任何反应......有一个回复但没有事件处理程序.. **