<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<script type="text/javascript">
function XmlPost(str)
{
var webFileUrl="";
document.all("<% =Lbx_ClassThree.ClientID %>").length=0;
if(str==1)
{
webFileUrl = "?oneid=" + document.all("<% =Lbx_ClassOne.ClientID %>").value;
document.all("<% =Lbx_ClassTwo.ClientID %>").length=0;
}
else
{
webFileUrl = "?oneid=" + document.all("<% =Lbx_ClassOne.ClientID %>").value+"&twoid="+document.all("<% =Lbx_ClassTwo.ClientID %>").value;
}
var result = "";
var xmlHttp = new ActiveXObject("MSXML2.XMLHTTP");
xmlHttp.open("Post", webFileUrl, false);
xmlHttp.send("");
result = xmlHttp.responseText;
if(result != "")
{
var piArray = result.split(",");
if(str==1)
{
for(var i=0; i<piArray.length; i++)
{
var ary1 = piArray[i].toString().split("|");
document.all("<% =Lbx_ClassTwo.ClientID %>").options.add(new Option(ary1[1].toString(),ary1[0].toString()));
}
}
else
{
for(var i=0; i>piArray.length; i++)
{
var ary1 = piArray[i].toString().split("|");
document.all("<% =Lbx_ClassThree.ClientID %>").options.add(new Option(ary1[1].toString(),ary1[0].toString()));
}
}
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ListBox ID="Lbx_ClassOne" runat="server"></asp:ListBox> <asp:ListBox ID="Lbx_ClassTwo" runat="server" ></asp:ListBox>
<asp:ListBox ID="Lbx_ClassThree" runat="server" ></asp:ListBox>
</form>
</body>
</html>
。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;public partial class Member_liandong_liandong : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string strOneid = "", strTwoid = "";
if (Request["oneid"] != null && Request["oneid"].ToString() != "")
{
strOneid = Request["oneid"].ToString();
}
if (Request["twoid"] != null && Request["twoid"].ToString() != "")
{
strTwoid = Request["twoid"].ToString();
}
if (strOneid != "")
{
Lbx_Class_Bind(strOneid, strTwoid);
//Lbx_Class_Bind(strOneid, strTwoid);
}
if (!this.IsPostBack)
{
Lbx_ClassOne_Bind();
Lbx_ClassOne.Attributes.Add("onchange", "XmlPost(1)");
Lbx_ClassTwo.Attributes.Add("onchange", "XmlPost(2)");
}
}
private void Lbx_ClassOne_Bind()
{
string strSQL;
strSQL = "select * from area where oneid<>0 and twoid=0 and threeid=0 order by sort";
Lbx_ClassOne.DataSource =Class1.GetDataReader(strSQL); //此处为我写的一个取DataReader对象的类
Lbx_ClassOne.DataTextField = "areaname";
Lbx_ClassOne.DataValueField = "oneid";
Lbx_ClassOne.DataBind();
}
private void Lbx_Class_Bind(string oneid, string twoid) {
string strSQL = "", idname = "";
if (oneid != "" && twoid == "")
{
strSQL = "select * from area where twoid<>0 and threeid=0 and oneid=" + oneid + " order by sort";
idname = "twoid";
}
if (oneid != "" && twoid != "") {
strSQL = "select * from area where threeid<>0 and oneid=" + oneid + " and twoid=" + twoid + " order by sort";
idname = "threeid";
}
string mystr = "";
IDataReader dr = Class1.GetDataReader(strSQL); //此处为我写的一个取DataReader对象的类
while (dr.Read())
{
mystr += "," + dr[idname].ToString() + "|" + dr["areaname"].ToString();
}
if (mystr != "")
{
mystr = mystr.Substring(1);
}
dr.Close();
this.Response.Write(mystr);
this.Response.End();
}
}
<head id="Head1" runat="server">
<script type="text/javascript">
function XmlPost(str)
{
var webFileUrl="";
document.all("<% =Lbx_ClassThree.ClientID %>").length=0;
if(str==1)
{
webFileUrl = "?oneid=" + document.all("<% =Lbx_ClassOne.ClientID %>").value;
document.all("<% =Lbx_ClassTwo.ClientID %>").length=0;
}
else
{
webFileUrl = "?oneid=" + document.all("<% =Lbx_ClassOne.ClientID %>").value+"&twoid="+document.all("<% =Lbx_ClassTwo.ClientID %>").value;
}
var result = "";
var xmlHttp = new ActiveXObject("MSXML2.XMLHTTP");
xmlHttp.open("Post", webFileUrl, false);
xmlHttp.send("");
result = xmlHttp.responseText;
if(result != "")
{
var piArray = result.split(",");
if(str==1)
{
for(var i=0; i<piArray.length; i++)
{
var ary1 = piArray[i].toString().split("|");
document.all("<% =Lbx_ClassTwo.ClientID %>").options.add(new Option(ary1[1].toString(),ary1[0].toString()));
}
}
else
{
for(var i=0; i>piArray.length; i++)
{
var ary1 = piArray[i].toString().split("|");
document.all("<% =Lbx_ClassThree.ClientID %>").options.add(new Option(ary1[1].toString(),ary1[0].toString()));
}
}
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ListBox ID="Lbx_ClassOne" runat="server"></asp:ListBox> <asp:ListBox ID="Lbx_ClassTwo" runat="server" ></asp:ListBox>
<asp:ListBox ID="Lbx_ClassThree" runat="server" ></asp:ListBox>
</form>
</body>
</html>
。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;public partial class Member_liandong_liandong : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string strOneid = "", strTwoid = "";
if (Request["oneid"] != null && Request["oneid"].ToString() != "")
{
strOneid = Request["oneid"].ToString();
}
if (Request["twoid"] != null && Request["twoid"].ToString() != "")
{
strTwoid = Request["twoid"].ToString();
}
if (strOneid != "")
{
Lbx_Class_Bind(strOneid, strTwoid);
//Lbx_Class_Bind(strOneid, strTwoid);
}
if (!this.IsPostBack)
{
Lbx_ClassOne_Bind();
Lbx_ClassOne.Attributes.Add("onchange", "XmlPost(1)");
Lbx_ClassTwo.Attributes.Add("onchange", "XmlPost(2)");
}
}
private void Lbx_ClassOne_Bind()
{
string strSQL;
strSQL = "select * from area where oneid<>0 and twoid=0 and threeid=0 order by sort";
Lbx_ClassOne.DataSource =Class1.GetDataReader(strSQL); //此处为我写的一个取DataReader对象的类
Lbx_ClassOne.DataTextField = "areaname";
Lbx_ClassOne.DataValueField = "oneid";
Lbx_ClassOne.DataBind();
}
private void Lbx_Class_Bind(string oneid, string twoid) {
string strSQL = "", idname = "";
if (oneid != "" && twoid == "")
{
strSQL = "select * from area where twoid<>0 and threeid=0 and oneid=" + oneid + " order by sort";
idname = "twoid";
}
if (oneid != "" && twoid != "") {
strSQL = "select * from area where threeid<>0 and oneid=" + oneid + " and twoid=" + twoid + " order by sort";
idname = "threeid";
}
string mystr = "";
IDataReader dr = Class1.GetDataReader(strSQL); //此处为我写的一个取DataReader对象的类
while (dr.Read())
{
mystr += "," + dr[idname].ToString() + "|" + dr["areaname"].ToString();
}
if (mystr != "")
{
mystr = mystr.Substring(1);
}
dr.Close();
this.Response.Write(mystr);
this.Response.End();
}
}
解决方案 »
- AspNetPager1 分页只显示前两页,奇怪不解...
- 请教一个关于asp:BulletedList控件选中项变色的问题
- ========>dropdownlist 怎么改 下拉框里 字体大小
- 在线求思路...复杂数据表导出到excel...
- C#类中用session需要导入什么命名空间啊
- 如何程序控制输出信息为"n行n列"?
- 找不到文件或程序集名称 调试难题求救
- 我是一只菜菜鸟 程序运行有错误请各位高手指点
- !!!!!!高分赠送,请教更新问题???????请大家来看看,解决后立刻给分!!!
- 请来帮助我一下,关于DataTable使我郁闷了2天的问题(高手请进!)
- 帮我补充完整代码
- |zyciis| 老问题:如何获取当前页面是由哪个页面Response.Redirect过来的
主键(自增长) ID int 4
areaname nvarchar 50
oneid int 4
twoid int 4
threeid int 4
sort int 4