protected System.Web.UI.WebControls.Label myLabel;
protected System.Web.UI.WebControls.DropDownList DeptName;
protected System.Web.UI.WebControls.RequiredFieldValidator Requiredfieldvalidator2;
protected System.Web.UI.WebControls.RequiredFieldValidator Requiredfieldvalidator1;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator;
protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator;
protected System.Web.UI.WebControls.RequiredFieldValidator Requiredfieldvalidator3;
protected System.Web.UI.WebControls.DropDownList ClassName;
protected System.Web.UI.WebControls.TextBox StuName;
protected System.Web.UI.WebControls.TextBox StuId;
protected System.Web.UI.WebControls.Button Submit;
public string a;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(!Page.IsPostBack)
{
string userclass;
userclass=(string)Session["userclass"];
if(userclass.Trim()!="系统管理员")
{
Page.Visible=false;
}
else
{
getDept();
}
}
}
private void getDept()
{
string da=(string)Session["userclass"] ;
string deptname=(string)Session["deptname"];
if(da.Trim()=="系统管理员")
{
string con=ConfigurationSettings.AppSettings["dsn"];
SqlConnection myConnection = new SqlConnection(con);
myConnection.Open();
SqlDataAdapter selDeptAll = new SqlDataAdapter();
selDeptAll.SelectCommand=new SqlCommand("sp_selDeptAll",myConnection);
selDeptAll.SelectCommand.CommandType=CommandType.StoredProcedure ;
DataSet ds = new DataSet();
selDeptAll.Fill(ds,"DeptName");
DeptName.DataSource=ds;
DeptName.DataTextField="deptname";
DeptName.DataValueField="deptid";
DeptName.DataBind();
getClass();
myConnection.Close();
}
else
{
ListItem d=new ListItem(deptname,deptname);
DeptName.Items.Add(d);
}
}
protected void DeptName_SelectedIndexChanged(object sender, EventArgs e)
{
string da=(string)Session["userclass"] ;
string classname=(string)Session["classname"];
if(da.Trim()=="系统管理员")
{
string con=ConfigurationSettings.AppSettings["dsn"];
SqlConnection myConnection = new SqlConnection(con);
myConnection.Open();
string sel;
SqlDataAdapter selclass ;
a=DeptName.SelectedItem.Value;
sel="select classname from db_Class where deptid IN (select deptid from db_dept WHERE deptid="+a+")";
selclass = new SqlDataAdapter(sel,myConnection);
DataSet ds = new DataSet();
selclass.Fill(ds,"Class");
ClassName.DataSource=ds;
ClassName.DataTextField="classname";
ClassName.DataValueField="classname";
ClassName.DataBind();
myConnection.Close();
}
else
{
ListItem d=new ListItem(classname,classname);
ClassName.Items.Add(d);
}
}
private void getClass()
{
string da=(string)Session["userclass"] ;
string classname=(string)Session["classname"];
if(da.Trim()=="系统管理员")
{
string con=ConfigurationSettings.AppSettings["dsn"];
SqlConnection myConnection = new SqlConnection(con);
myConnection.Open();
string sel;
SqlDataAdapter selclass ;
a=DeptName.SelectedItem.Value;
sel="select classname from db_Class where deptid IN (select deptid from db_dept WHERE deptid="+a+")";
selclass = new SqlDataAdapter(sel,myConnection);
DataSet ds = new DataSet();
selclass.Fill(ds,"Class");
ClassName.DataSource=ds;
ClassName.DataTextField="classname";
ClassName.DataValueField="classname";
ClassName.DataBind();
myConnection.Close();
}
else
{
ListItem d=new ListItem(classname,classname);
ClassName.Items.Add(d);
}
}
问题是似乎SelectedIndexChanged不起作用,我改变Dropdownlist的取值,下拉框ClassName的数据还是不变。不知道是什么问题?