所有下拉列表都在单个selectedIndexchanged处重置

时间:2012-03-11 09:58:29

标签: c#

我有这个项目我在注册表上工作有四个下拉列表。两个已经从数据库填充页面加载事件

        if (!IsPostBack)
        {

            if (!getState()) { return; }
            if (!GetFaculty()) { return; }

        }

其余两个已填入两个(州和教职员工)的selectIndexchange

  protected void ddlFaculty_OnSelectedIndexChanged(object sender, EventArgs e)
  {
        if (Page.IsPostBack) 
        { 
            try
            {
                string sqltext = @"Select Name from Department where FacultyID=" + this.ddlFaculty.SelectedValue.ToString();
                List<Department> mlist = new List<Department>();
                mlist = ServiceProvider.Instance().GetDepartmentService().GetDepartment_GetDepartment(sqltext);
                if (mlist.IsNullOrEmpty()) { return; }
                this.ddlDepartment.DataSource = mlist;
                this.ddlDepartment.DataTextField = "Name";
                this.ddlDepartment.DataValueField = "DepartmentID";
                this.ddlDepartment.DataBind();
                this.ddlDepartment.Items.Insert(0, new ListItem("--Select Department--", "0"));

            }
            catch (Exception ex) { return; }
        }

    }

    protected void ddstate_OnSelectedIndexChanged(object sender, EventArgs e)
    {
        if (Page.IsPostBack)
        { 

            try
            {
                string sqltext = @"Select Name from University where StateID=" + this.ddlState.SelectedValue.ToString();
                List<University> mlist = new List<University>();
                mlist = ServiceProvider.Instance().GetUniversityService().GetUniversity_UniversityName(sqltext);
                this.dDUniversity.DataSource = mlist;
                this.dDUniversity.DataTextField = "Name";
                this.dDUniversity.DataValueField = "UniversityID";
                this.dDUniversity.DataBind();
                this.dDUniversity.Items.Insert(0, new ListItem("-- Select University--", "0"));
                this.dDUniversity.SelectedIndex = 0;

            }
            catch (Exception ex) { return; };
        }
    }

现在的问题是,一旦我从ddUniversity中的ddstate的selectedIndexChanged中选择一个值就可以正常工作,然后从ddDepartment中选择ddfaculty的selectedIndexChanged中的值将自动重置ddUniversity并同时单击注册按钮ddUniversity和ddDepartment的每一件事。 这是我的HTML代码

1 个答案:

答案 0 :(得分:0)

尝试使用UpdatePanels或使用普通的AJAX来加载DropDowns