标题:这是我ASP。net 实训的作品!我有些地方不明白,想问下高手!小弟感激不尽! ...
只看楼主
自强
Rank: 3Rank: 3
等 级:论坛游侠
威 望:1
帖 子:132
专家分:130
注 册:2011-10-3
结帖率:96.77%
已结贴  问题点数:20 回复次数:2 
这是我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("==请选择==",""));
        }

        
    }
}
搜索更多相关主题的帖子: class department public 实训 
2011-12-14 16:05
牛腩
Rank: 3Rank: 3
来 自:南宁
等 级:论坛游侠
威 望:1
帖 子:59
专家分:161
注 册:2007-6-3
得分:20 
Request.Form["zhuanyeList"];是获取URL中的参数,如果你的网址是
http://
那么string spc_id = Request.Form["zhuanyeList"];之后
spc_id就等于 343
2011-12-14 17:30
自强
Rank: 3Rank: 3
等 级:论坛游侠
威 望:1
帖 子:132
专家分:130
注 册:2011-10-3
得分:0 
回复 2楼 牛腩
string spc_id= zhuanyeList.SelectedIndex.ToString(); 我用了这个后  spc_id一直获取的值是1

成为一名真正合格的程序设计人员,是我的梦想……我希望我的梦一直保持下去,直到我从这个世界消失……
2011-12-14 19:47



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-357738-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.144985 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved