a.aspx HTML
<%
@ Page Language
=
"
C#
"
AutoEventWireup
=
"
true
"
CodeFile
=
"
a.aspx.cs
"
Inherits
=
"
a
"
EnableEventValidation
=
"
false
"
%>
<! DOCTYPE html PUBLIC " -//W3C//DTD XHTML 1.0 Transitional//EN " " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd " >
< html xmlns = " http://www.w3.org/1999/xhtml " >
< head id = " Head1 " runat = " server " >
< title > Untitled Page </ title >
< script type = " text/javascript " >
function load(state,state1)
... {
var drp2 = document.getElementById("DropDownList2");
for (i = drp2.length; i >= 0; i--)
...{
drp2.options.remove(i);
}
var oHttpReq = new ActiveXObject("MSXML2.XMLHTTP");
var oDoc = new ActiveXObject("MSXML2.DOMDocument");
oHttpReq.open("POST", "b.aspx?state="+state+"&state1="+state1, false);
oHttpReq.send("");
result = oHttpReq.responseText;
oDoc.loadXML(result);
//这个是用DataSet里的数据,为DropDownList2要显示的字段,也就是b.aspx.cs里写的SQL语句的字段
items1 = oDoc.selectNodes("//NewDataSet/Table/goodsDtlId");
items2 = oDoc.selectNodes("//NewDataSet/Table/goodsDtlType");
var itemsLength=items1.length;
for(i=0;i<itemsLength;i++)
//将小类的类名和编号赋予DropDownList2
...{
var newOption = document.createElement("OPTION");
newOption.text=items2[i].text;
newOption.value=items1[i].text;
drp2.options.add(newOption);
}
}
function load1(state,state1)
... {
var drp3 = document.getElementById("DropDownList3");
for (i = drp3.length; i >= 0; i--)
...{
drp3.options.remove(i);
}
var oHttpReq = new ActiveXObject("MSXML2.XMLHTTP");
var oDoc = new ActiveXObject("MSXML2.DOMDocument");
oHttpReq.open("POST", "c.aspx?state="+state+"&state1="+state1, false);
oHttpReq.send("");
result = oHttpReq.responseText;
oDoc.loadXML(result);
items1 = oDoc.selectNodes("//NewDataSet/Table/EpId"); //这个是用DataSet里的数据
items2 = oDoc.selectNodes("//NewDataSet/Table/EpRealName"); //为DropDownList3要显示的字段
var itemsLength=items1.length;
for(i=0;i<itemsLength;i++)
//将小类的类名和编号赋予DropDownList3
...{
var newOption = document.createElement("OPTION");
newOption.text=items2[i].text;
newOption.value=items1[i].text;
drp3.options.add(newOption);
}
}
function aa()
... {
var c=document.getElementById("DropDownList1").value;
document.getElementById("HiddenField1").value=c;
c=document.getElementById("DropDownList2").value;
document.getElementById("HiddenField2").value=c;
c=document.getElementById("DropDownList3").value;
document.getElementById("HiddenField3").value=c;
}
</ script >
</ head >
< body >
< form id = " form1 " runat = " server " >
< div >
< asp:DropDownList id = " DropDownList1 " runat = " server " >
</ asp:DropDownList >
< asp:DropDownList id = " DropDownList2 " runat = " server " ></ asp:DropDownList >
< asp:DropDownList ID = " DropDownList3 " runat = " server " >
</ asp:DropDownList >
< asp:HiddenField ID = " HiddenField1 " runat = " server " />
< asp:HiddenField ID = " HiddenField2 " runat = " server " />
< asp:HiddenField ID = " HiddenField3 " runat = " server " />
< asp:Button ID = " Button1 " runat = " server " OnClientClick = " javascript:aa(); " OnClick = " Button1_Click " Text = " Button " />
< asp:Label ID = " Label1 " runat = " server " Text = " Label " ></ asp:Label >
</ div >
</ form >
</ body >
</ html >
<! DOCTYPE html PUBLIC " -//W3C//DTD XHTML 1.0 Transitional//EN " " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd " >
< html xmlns = " http://www.w3.org/1999/xhtml " >
< head id = " Head1 " runat = " server " >
< title > Untitled Page </ title >
< script type = " text/javascript " >
function load(state,state1)
... {
var drp2 = document.getElementById("DropDownList2");
for (i = drp2.length; i >= 0; i--)
...{
drp2.options.remove(i);
}
var oHttpReq = new ActiveXObject("MSXML2.XMLHTTP");
var oDoc = new ActiveXObject("MSXML2.DOMDocument");
oHttpReq.open("POST", "b.aspx?state="+state+"&state1="+state1, false);
oHttpReq.send("");
result = oHttpReq.responseText;
oDoc.loadXML(result);
//这个是用DataSet里的数据,为DropDownList2要显示的字段,也就是b.aspx.cs里写的SQL语句的字段
items1 = oDoc.selectNodes("//NewDataSet/Table/goodsDtlId");
items2 = oDoc.selectNodes("//NewDataSet/Table/goodsDtlType");
var itemsLength=items1.length;
for(i=0;i<itemsLength;i++)
//将小类的类名和编号赋予DropDownList2
...{
var newOption = document.createElement("OPTION");
newOption.text=items2[i].text;
newOption.value=items1[i].text;
drp2.options.add(newOption);
}
}
function load1(state,state1)
... {
var drp3 = document.getElementById("DropDownList3");
for (i = drp3.length; i >= 0; i--)
...{
drp3.options.remove(i);
}
var oHttpReq = new ActiveXObject("MSXML2.XMLHTTP");
var oDoc = new ActiveXObject("MSXML2.DOMDocument");
oHttpReq.open("POST", "c.aspx?state="+state+"&state1="+state1, false);
oHttpReq.send("");
result = oHttpReq.responseText;
oDoc.loadXML(result);
items1 = oDoc.selectNodes("//NewDataSet/Table/EpId"); //这个是用DataSet里的数据
items2 = oDoc.selectNodes("//NewDataSet/Table/EpRealName"); //为DropDownList3要显示的字段
var itemsLength=items1.length;
for(i=0;i<itemsLength;i++)
//将小类的类名和编号赋予DropDownList3
...{
var newOption = document.createElement("OPTION");
newOption.text=items2[i].text;
newOption.value=items1[i].text;
drp3.options.add(newOption);
}
}
function aa()
... {
var c=document.getElementById("DropDownList1").value;
document.getElementById("HiddenField1").value=c;
c=document.getElementById("DropDownList2").value;
document.getElementById("HiddenField2").value=c;
c=document.getElementById("DropDownList3").value;
document.getElementById("HiddenField3").value=c;
}
</ script >
</ head >
< body >
< form id = " form1 " runat = " server " >
< div >
< asp:DropDownList id = " DropDownList1 " runat = " server " >
</ asp:DropDownList >
< asp:DropDownList id = " DropDownList2 " runat = " server " ></ asp:DropDownList >
< asp:DropDownList ID = " DropDownList3 " runat = " server " >
</ asp:DropDownList >
< asp:HiddenField ID = " HiddenField1 " runat = " server " />
< asp:HiddenField ID = " HiddenField2 " runat = " server " />
< asp:HiddenField ID = " HiddenField3 " runat = " server " />
< asp:Button ID = " Button1 " runat = " server " OnClientClick = " javascript:aa(); " OnClick = " Button1_Click " Text = " Button " />
< asp:Label ID = " Label1 " runat = " server " Text = " Label " ></ asp:Label >
</ div >
</ form >
</ body >
</ html >
a.aspx.cs
using
System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class a : System.Web.UI.Page
... {
SqlConnection con;
protected void Page_Load(object sender, EventArgs e)
...{
if (!Page.IsPostBack)
...{
con = new SqlConnection("server=.;database=runskyDB;uid=sa");
string sql = "select * from goodsType";
SqlDataAdapter da = new SqlDataAdapter(sql, con);
DataSet ds = new DataSet();
da.Fill(ds);
this.DropDownList1.DataSource = ds.Tables[0].DefaultView;
this.DropDownList1.DataTextField = "goodsType";
this.DropDownList1.DataValueField = "goodsId";
this.DropDownList1.DataBind();
// 这里是绑定客户端事件,当第一个DropDownList的选项改变时激发下面的事件onchange,这个事件将调用一个客户端方法load()
this.DropDownList1.Attributes.Add("onchange", "load(this.options[this.selectedIndex].value)");
this.DropDownList2.Attributes.Add("onchange", "load1(this.options[this.selectedIndex].value,DropDownList1.options[DropDownList1.selectedIndex].value)");
DropDownList1.Items.Add("---请选择---");
}
}
protected void Button1_Click(object sender, EventArgs e)
...{
Label1.Text ="dropdown1:"+ HiddenField1.Value;
Label1.Text += " dropdown2:" + HiddenField2.Value;
Label1.Text += "dropdown3:" + HiddenField3.Value;
}b.aspx.cs
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class a : System.Web.UI.Page
... {
SqlConnection con;
protected void Page_Load(object sender, EventArgs e)
...{
if (!Page.IsPostBack)
...{
con = new SqlConnection("server=.;database=runskyDB;uid=sa");
string sql = "select * from goodsType";
SqlDataAdapter da = new SqlDataAdapter(sql, con);
DataSet ds = new DataSet();
da.Fill(ds);
this.DropDownList1.DataSource = ds.Tables[0].DefaultView;
this.DropDownList1.DataTextField = "goodsType";
this.DropDownList1.DataValueField = "goodsId";
this.DropDownList1.DataBind();
// 这里是绑定客户端事件,当第一个DropDownList的选项改变时激发下面的事件onchange,这个事件将调用一个客户端方法load()
this.DropDownList1.Attributes.Add("onchange", "load(this.options[this.selectedIndex].value)");
this.DropDownList2.Attributes.Add("onchange", "load1(this.options[this.selectedIndex].value,DropDownList1.options[DropDownList1.selectedIndex].value)");
DropDownList1.Items.Add("---请选择---");
}
}
protected void Button1_Click(object sender, EventArgs e)
...{
Label1.Text ="dropdown1:"+ HiddenField1.Value;
Label1.Text += " dropdown2:" + HiddenField2.Value;
Label1.Text += "dropdown3:" + HiddenField3.Value;
}b.aspx.cs
using
System;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Text;
using System.Xml;
public partial class b : System.Web.UI.Page
... {
protected void Page_Load(object sender, EventArgs e)
...{
string shengNo = Request["state"].ToString();
SqlConnection con = new SqlConnection("server=.;database=runskyDB;uid=sa");
//这是DropDownList2要显示的字段
string sql = "select goodsDtlId,goodsDtlType from goodsTypeDtl where gid='" + shengNo + "'";
SqlDataAdapter da = new SqlDataAdapter(sql,con);
DataSet ds = new DataSet();
da.Fill(ds);
XmlTextWriter writer = new XmlTextWriter(Response.OutputStream, Encoding.UTF8);
writer.Formatting = Formatting.Indented;
writer.Indentation = 4;
writer.IndentChar = ' ';
writer.WriteStartDocument();
ds.WriteXml(writer);
writer.Flush();
Response.End();
writer.Close();
}
}
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Text;
using System.Xml;
public partial class b : System.Web.UI.Page
... {
protected void Page_Load(object sender, EventArgs e)
...{
string shengNo = Request["state"].ToString();
SqlConnection con = new SqlConnection("server=.;database=runskyDB;uid=sa");
//这是DropDownList2要显示的字段
string sql = "select goodsDtlId,goodsDtlType from goodsTypeDtl where gid='" + shengNo + "'";
SqlDataAdapter da = new SqlDataAdapter(sql,con);
DataSet ds = new DataSet();
da.Fill(ds);
XmlTextWriter writer = new XmlTextWriter(Response.OutputStream, Encoding.UTF8);
writer.Formatting = Formatting.Indented;
writer.Indentation = 4;
writer.IndentChar = ' ';
writer.WriteStartDocument();
ds.WriteXml(writer);
writer.Flush();
Response.End();
writer.Close();
}
}
c.aspx.cs
using
System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Text;
using System.IO;
using System.Xml;
public partial class c : System.Web.UI.Page
... {
protected void Page_Load(object sender, EventArgs e)
...{
string shengNo = Request["state"].ToString();
string shengNo1 = Request["state1"].ToString();
SqlConnection con = new SqlConnection("server=.;database=runskyDB;uid=sa");
//这是DropDownList3要显示的字段
string sql = "select EpId,EpRealName from EpUser where EpDis_Type=" + shengNo1 + " and EpDis_TypeDtl=" + shengNo;
SqlDataAdapter da = new SqlDataAdapter(sql, con);
DataSet ds = new DataSet();
da.Fill(ds);
XmlTextWriter writer = new XmlTextWriter(Response.OutputStream, Encoding.UTF8);
writer.Formatting = Formatting.Indented;
writer.Indentation = 4;
writer.IndentChar = ' ';
writer.WriteStartDocument();
ds.WriteXml(writer);
writer.Flush();
Response.End();
writer.Close();
}
}
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Text;
using System.IO;
using System.Xml;
public partial class c : System.Web.UI.Page
... {
protected void Page_Load(object sender, EventArgs e)
...{
string shengNo = Request["state"].ToString();
string shengNo1 = Request["state1"].ToString();
SqlConnection con = new SqlConnection("server=.;database=runskyDB;uid=sa");
//这是DropDownList3要显示的字段
string sql = "select EpId,EpRealName from EpUser where EpDis_Type=" + shengNo1 + " and EpDis_TypeDtl=" + shengNo;
SqlDataAdapter da = new SqlDataAdapter(sql, con);
DataSet ds = new DataSet();
da.Fill(ds);
XmlTextWriter writer = new XmlTextWriter(Response.OutputStream, Encoding.UTF8);
writer.Formatting = Formatting.Indented;
writer.Indentation = 4;
writer.IndentChar = ' ';
writer.WriteStartDocument();
ds.WriteXml(writer);
writer.Flush();
Response.End();
writer.Close();
}
}