代码如下:
/// <summary>
/// 绑定学生下拉菜单
/// </summary>
private void BindStu()
{
Response.Write("<script>");
Response.Write("alert(" + this.Request["sNum"].ToString() + ");");
Response.Write("</script>");
string sql = " select c_StuNumber,c_StuName from t_Student where c_ClassNum='" + this.Request["sNum"].ToString() + "'";
this.Ddl_Stu.DataSource = m_DataBase.GetDataSet(sql,"0").Tables[0];
this.Ddl_Stu.DataTextField = "c_StuName";
this.Ddl_Stu.DataValueField = "c_StuNumber";
this.Ddl_Stu.DataBind();
}
/// <summary>
/// 绑定班级信息下拉菜单
/// </summary>
private void BindCla()
{
string sql = " select c_ClassNumber,c_ClassName from t_ClassMessage ";
this.Ddl_Class.DataSource = m_DataBase.GetDataSet(sql, "0").Tables[0];
this.Ddl_Class.DataTextField = "c_ClassName";
this.Ddl_Class.DataValueField = "c_ClassNumber";
this.Ddl_Class.DataBind();
this.Ddl_Class.Attributes.Add("onchange", "javascript:return show('" + Ddl_Class.SelectedValue + "')");
}
前台ajax
var xmlHttp;
function createXMLHttpRequest()
{
if (window.ActiveXObject)
{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if (window.XMLHttpRequest)
{
xmlHttp = new XMLHttpRequest();
}
}
function show(sNum)
{
createXMLHttpRequest();
xmlHttp.open("GET", "/Web/Leader/MathNum.aspx?sNum="+escape(sNum),false);
xmlHttp.onreadystatechange = callback;
xmlHttp.send(null);
}
function callback()
{
if (xmlHttp.readyState == 4) {
if (xmlHttp.status == 200) {
}
}
}
如果按照你这样的写法,需要在Page_Load中用Request获取sNum的值然后调用方法。
this.Request["sNum"].ToString()这里你似乎接收得有问题的,如果你需要这样子操作,那你需要确保BindStu这个方法在MathNum.aspx中,其次你需要确保在调用MathNum.aspx时能激发BindStu方法,简单说你可以把这个方法写入Page_Load中,这样子就可以使用this.Request["sNum"].ToString()来获取你ajax传入的值了
用JQuery的get方法调用,在Page_Load中调用Page.Request["sNum"],判断是否是Null