大哥们帮我看看下面的代码,不知道为什么不能实现无刷新联动
webform2.aspx.cs 中的代码
protected void Page_Load(object sender, EventArgs e)
{
db dbase = new db();
SqlConnection con = dbase.getConn();
string sql = @"select * from ZoneInfoTB";
SqlDataAdapter da = new SqlDataAdapter(sql, con);
DataSet ds = new DataSet();
try
{
con.Open();
da.Fill(ds, "ZoneInfoTB");
this.DropDownList1.DataSource = ds;
this.DropDownList1.DataTextField = "DM_Desc";
this.DropDownList1.DataValueField = "DM_ID";
this.DropDownList1.DataBind();
this.DropDownList1.Attributes.Add("onchange", "load(this.options[this.selectedIndex].value)");
}
catch (Exception err)
{ }
finally
{
con.Close();
con.Dispose();
}
}
webform.aspx中的代码
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="WebForm.aspx.cs" Inherits="SCDT_WebForm" %><!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 runat="server">
<title>无标题页</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
<script>
function load(state)
{
var drp2 = document.getElementById("DropDownList2");
for(var i = 0;i<=drp2.options.length -1;i++)
{
drp2.remove(i);
}
var oHttpReq = new ActiveXObject("MSXML2.XMLHTTP");
var oDoc = new ActiveXObject("MSXML2.DOMDocument");
oHttpReq.open("POST", "webform6.aspx?state="+state, false);
oHttpReq.send("");
result = oHttpReq.responseText;
oDoc.loadXML(result);
items = oDoc.selectNodes("//city/jghqdatatb");
for (var item = items.nextNode(); item; item = items.nextNode())
{
var city = item.selectSingleNode("//et").nodeTypedValue;
var newOption = document.createElement("OPTION");
newOption.text = city;
newOption.value = city;
drp2.options.add(newOption);
}
}
</script>
</head>
<body MS_POSITIONING="flowLayout"> <form id="Form1" method="post" runat="server">
<div>
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>
<asp:DropDownList ID="DropDownList2" runat="server">
</asp:DropDownList></div>
</form>
</body>
</html>
webform6.aspx.cs 中的代码 protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["state"] != null)
{
string state = Request.QueryString["state"].ToString();
db dbase=new db();
SqlConnection con =dbase.getConn();
string sql=@"select et from jghqdatatb where InfoFromZoneID = '" + state + "'";
SqlDataAdapter da = new SqlDataAdapter(sql, con);
DataSet ds = new DataSet();
da.Fill(ds, "city");
XmlTextWriter writer = new XmlTextWriter(Response.OutputStream, Response.ContentEncoding);
writer.Formatting = Formatting.Indented;
writer.Indentation = 4;
writer.IndentChar = ' ';
ds.WriteXml(writer);
writer.Flush();
Response.End();
writer.Close();
}
}
webform2.aspx.cs 中的代码
protected void Page_Load(object sender, EventArgs e)
{
db dbase = new db();
SqlConnection con = dbase.getConn();
string sql = @"select * from ZoneInfoTB";
SqlDataAdapter da = new SqlDataAdapter(sql, con);
DataSet ds = new DataSet();
try
{
con.Open();
da.Fill(ds, "ZoneInfoTB");
this.DropDownList1.DataSource = ds;
this.DropDownList1.DataTextField = "DM_Desc";
this.DropDownList1.DataValueField = "DM_ID";
this.DropDownList1.DataBind();
this.DropDownList1.Attributes.Add("onchange", "load(this.options[this.selectedIndex].value)");
}
catch (Exception err)
{ }
finally
{
con.Close();
con.Dispose();
}
}
webform.aspx中的代码
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="WebForm.aspx.cs" Inherits="SCDT_WebForm" %><!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 runat="server">
<title>无标题页</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
<script>
function load(state)
{
var drp2 = document.getElementById("DropDownList2");
for(var i = 0;i<=drp2.options.length -1;i++)
{
drp2.remove(i);
}
var oHttpReq = new ActiveXObject("MSXML2.XMLHTTP");
var oDoc = new ActiveXObject("MSXML2.DOMDocument");
oHttpReq.open("POST", "webform6.aspx?state="+state, false);
oHttpReq.send("");
result = oHttpReq.responseText;
oDoc.loadXML(result);
items = oDoc.selectNodes("//city/jghqdatatb");
for (var item = items.nextNode(); item; item = items.nextNode())
{
var city = item.selectSingleNode("//et").nodeTypedValue;
var newOption = document.createElement("OPTION");
newOption.text = city;
newOption.value = city;
drp2.options.add(newOption);
}
}
</script>
</head>
<body MS_POSITIONING="flowLayout"> <form id="Form1" method="post" runat="server">
<div>
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>
<asp:DropDownList ID="DropDownList2" runat="server">
</asp:DropDownList></div>
</form>
</body>
</html>
webform6.aspx.cs 中的代码 protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["state"] != null)
{
string state = Request.QueryString["state"].ToString();
db dbase=new db();
SqlConnection con =dbase.getConn();
string sql=@"select et from jghqdatatb where InfoFromZoneID = '" + state + "'";
SqlDataAdapter da = new SqlDataAdapter(sql, con);
DataSet ds = new DataSet();
da.Fill(ds, "city");
XmlTextWriter writer = new XmlTextWriter(Response.OutputStream, Response.ContentEncoding);
writer.Formatting = Formatting.Indented;
writer.Indentation = 4;
writer.IndentChar = ' ';
ds.WriteXml(writer);
writer.Flush();
Response.End();
writer.Close();
}
}
解决方案 »
- 追踪分析的问题
- 菜鸟提问
- string s1 = "test1"; string s3 = string.Copy(s1); Console.Write((object)s1 == (object)s3); 为什么是FALSE
- 关于上一条,下一条新闻的问题
- C# excel数据导入
- 关于System.ComponentModel.Win32Exception的问题,请高手救命!!!
- 暑假在家无聊,谁能给个建议编个什么程序玩玩。。
- 求助!!!
- 如何在vs2003-c#中检测键盘的caps lock,num lock键状态?
- 请问,在C#中,能显示下面这种效果的是什么控件?
- 如何根据窗口句柄来获得他的进程ID
- 菜鸟送分啦~~关于sql的convert时间类型问题
XmlTextWriter writer = new XmlTextWriter(Response.OutputStream,Encoding.UTF8);
writer.Formatting = Formatting.Indented;
writer.Indentation = 4;
writer.IndentChar = ' ';
writer.WriteStartDocument();
ds.WriteXml(writer);
你可以将两个Dropdownlist放到一个updatepanel里面
后台第一个Dropdownlist的selectchange事件处理函数
处理第二个Dropdownlist的加载项