这是我ASP。net 实训的作品!我有些地方不明白,想问下高手!小弟感激不尽!
小弟我有如下代码,有些地方不带懂,就是红色字体那些,希望看到的高手能解释一下public partial class latecheck : System.Web.UI.Page
{
DB db = new DB();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)//页面不回传,页面初次加载时则加载系部信息
{
string strSql = "select * from department";
DataTable dt = db.reDt(strSql);
xibuList.DataSource = dt;
xibuList.DataTextField = "dept_name";
xibuList.DataValueField = "dept_id";
xibuList.DataBind();
xibuList.Items.Insert(0, new ListItem("==请选择==", ""));
classList.Items.Insert(0, new ListItem("==请选择==", ""));
zhuanyeList.Items.Insert(0, new ListItem("==请选择==", ""));
}
}
protected void xibuList_SelectedIndexChanged(object sender, EventArgs e)
{
string dept_id = xibuList.SelectedIndex.ToString();
if (dept_id != "")//系部选择不为空时加载专业信息
{
string strSql = "select * from special where dept_id="+dept_id;
DataTable dt = db.reDt(strSql);
zhuanyeList.DataSource = dt;
zhuanyeList.DataTextField = "spc_name";
zhuanyeList.DataValueField = "spc_id";
zhuanyeList.DataBind();
zhuanyeList.Items.Insert(0, new ListItem("==请选择==",""));
}
else
{
zhuanyeList.Items.Clear();
zhuanyeList.Items.Insert(0, new ListItem("==请选择==",""));
}
}
protected void zhuanyeList_SelectedIndexChanged(object sender, EventArgs e)
{
string spc_id = Request.Form["zhuanyeList"];//这里为什么要获取集合而不用 string spc_id= zhuanyeList.SelectedIndex.ToString();呢?
if (spc_id != "")//专业选择不为空时加载班级信息
{
string strSql = "select * from class where spc_id="+spc_id;
DataTable dt = db.reDt(strSql);
classList.DataSource = dt;
classList.DataTextField = "class_name";
classList.DataValueField = "class_id";
classList.DataBind();
classList.Items.Insert(0, new ListItem("==请选择==",""));
}
else
{
classList.Items.Clear();
classList.Items.Insert(0,new ListItem("==请选择==",""));
}
}
}