连动
来源:互联网 发布:123d design mac 编辑:程序博客网 时间:2024/05/16 01:32
<%@ WebHandler Language="C#" Class="GetCity" %>
using System;
using System.Web;
public class GetCity : IHttpHandler {
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
string CityResult = "";
Class2 csi = new Class2();
string type = context.Request.QueryString["ProvinceType"].ToString();
System.Data.DataTable gettable= csi.getCityInfo(Convert.ToInt32(type)).Tables[0];
for (int i = 0; i < gettable.Rows.Count; i++)
{
CityResult += gettable.Rows[i]["CityName"] + ";";
}
context.Response.Write(CityResult);
}
public bool IsReusable {
get {
return false;
}
}
}
页面代码
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="OmyGood.aspx.cs" Inherits="OmyGood" %>
<!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>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="DropDownList1" runat="server" >
</asp:DropDownList>
<asp:DropDownList ID="DropDownList2" runat="server">
</asp:DropDownList>
</div>
</form>
</body>
<script type="text/javascript" language="javascript">
var xmlHttp=false;
document.body.onload=function()
{
document.getElementById("DropDownList2").options[0]=new Option("请先选择省份");
}
function send_request()
{
if(window.XmlHttpRequest)
{
xmlHttp=new XMLHttpRequest();
}
else
{
try{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}catch(e)
{
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}catch(e)
{}
}
xmlHttp.onreadystatechange=GetCity;
xmlHttp.open("get","GetCity.ashx?provinceType="+document.getElementById('DropDownList1').value,true);
xmlHttp.send(null);
}
function GetCity()
{
if(xmlHttp.readyState==4&&xmlHttp.status==200)
{
if(xmlHttp.responseText!="")
{
var myarr=new Array(7);
var ResponseText=xmlHttp.responseText;
var pos=ResponseText.indexOf(";");
var i=0;
while(pos!=-1)
{
var myText=ResponseText.substring(0,pos);
if(myText!=""){
myarr[i]=myText;
i++;
}
ResponseText=ResponseText.substr(pos+1);
pos=ResponseText.indexOf(";");
continue;
}
for(var n=0;n<i;n++)
{
document.getElementById("DropDownList2").options[n]=new Option(myarr[n],"");
document.getElementById("DropDownList2").length=i;
}
}
else
{
document.getElementById("DropDownList2").options[0]=new Option("请先选择省份","");
document.getElementById("DropDownList2").length=1;
}
}
}
}
</script>
</html>
后台代码
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class OmyGood : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Class2 myclas = new Class2();
DataTable dt = myclas.getProvince().Tables[0];
if (!IsPostBack)
{
this.DropDownList1.DataSource = dt.DefaultView;
DropDownList1.DataValueField = "Pid";
DropDownList1.DataTextField = "PidName";
this.DropDownList1.DataBind();
DropDownList1.Attributes.Add("onchange", "send_request()");
}
}
}
- 连动
- 日期连动
- DropDownList连动菜单
- 省市连动
- XMLHTTP二级连动
- 多级的连动
- 二级连动
- 省市三级连动
- DynamicOptionList连动菜单
- 实现省市连动
- jsp连动菜单
- 二级连动
- DropDownList实现连动
- ext ComboBox 连动
- 连动反应
- 图片连动
- ecshop区域连动
- 二级连动
- 向ARM开发板移植mplayer
- ARM下一些常用库的移植
- 交叉编译 feng ~~提供参考
- Android开发之Animation(一)
- 产品设计的原则之一:精简你的产品
- 连动
- Android开发之Animation应用(二)
- 菜单栏
- 用好CSDN里面的资源
- Linux 进程原理简介
- 10. A cat may look at a king. 人人平等
- USB盘PE安装XP要点
- Goolge让一切变得简单
- GRUB详解