AJAX的问题.请高手们来看看!
我做了一个三级联动
前台
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
Namespace="System.Web.UI" TagPrefix="asp" %>
<!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:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
</div>
<asp:TextBox ID="TextBox1" runat="server" Style="z-index: 100; left: 203px; position: absolute;
top: 144px"></asp:TextBox>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:DropDownList ID="ddlProvince" runat="server" Style="z-index: 100; left: 466px;
position: absolute; top: 221px" AppendDataBoundItems="True" AutoPostBack="True" OnSelectedIndexChanged="ddlProvince_SelectedIndexChanged" Width="119px">
</asp:DropDownList>
<asp:DropDownList ID="ddlshi" runat="server" Style="z-index: 101; left: 240px;
position: absolute; top: 284px" AutoPostBack="True" Width="117px" OnSelectedIndexChanged="ddlshi_SelectedIndexChanged" Enabled="False">
</asp:DropDownList>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" Style="z-index: 103;
left: 79px; position: absolute; top: 234px" Enabled="False">
</asp:DropDownList>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>
CS文件
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ListItem item = new ListItem("-请选择省份-", "-1");
ddlProvince.Items.Insert(0, item);
this.ddlProvince.DataSource = ProvinceManager.GetAllProvince(); //获得全部省信息
this.ddlProvince.DataTextField = "pName";
this.ddlProvince.DataValueField = "pID";
this.ddlProvince.DataBind();
}
}
protected void ddlProvince_SelectedIndexChanged(object sender, EventArgs e)
{
int cid = Convert.ToInt32(this.ddlProvince.SelectedValue.ToString());
this.ddlshi.DataSource = CityManager.GetCityByPid(cid); //获得对应的城市信息
this.ddlshi.DataTextField = "cName";
this.ddlshi.DataValueField = "cID";
this.ddlshi.DataBind();
this.ddlshi.Enabled = true;
this.DropDownList1.Enabled = true;
}
protected void ddlshi_SelectedIndexChanged(object sender, EventArgs e)
{
int cid = Convert.ToInt32(this.ddlshi.SelectedValue.ToString());
this.DropDownList1.DataSource = CountyManager.GetCountyByCityID(cid); //获得对应的区县信息
this.DropDownList1.DataTextField = "cName";
this.DropDownList1.DataValueField = "cID";
this.DropDownList1.DataBind();
}
}
著名 ddlProvince 是省 ddlshi是城市 DropDownList1是区县
现在功能可以实现 但是选择省份后 页面还是刷新 真的不知道为什么 请高人指点
说明白点 或者直接告诉我代码哪错了;;
前台
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
Namespace="System.Web.UI" TagPrefix="asp" %>
<!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:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
</div>
<asp:TextBox ID="TextBox1" runat="server" Style="z-index: 100; left: 203px; position: absolute;
top: 144px"></asp:TextBox>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:DropDownList ID="ddlProvince" runat="server" Style="z-index: 100; left: 466px;
position: absolute; top: 221px" AppendDataBoundItems="True" AutoPostBack="True" OnSelectedIndexChanged="ddlProvince_SelectedIndexChanged" Width="119px">
</asp:DropDownList>
<asp:DropDownList ID="ddlshi" runat="server" Style="z-index: 101; left: 240px;
position: absolute; top: 284px" AutoPostBack="True" Width="117px" OnSelectedIndexChanged="ddlshi_SelectedIndexChanged" Enabled="False">
</asp:DropDownList>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" Style="z-index: 103;
left: 79px; position: absolute; top: 234px" Enabled="False">
</asp:DropDownList>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>
CS文件
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ListItem item = new ListItem("-请选择省份-", "-1");
ddlProvince.Items.Insert(0, item);
this.ddlProvince.DataSource = ProvinceManager.GetAllProvince(); //获得全部省信息
this.ddlProvince.DataTextField = "pName";
this.ddlProvince.DataValueField = "pID";
this.ddlProvince.DataBind();
}
}
protected void ddlProvince_SelectedIndexChanged(object sender, EventArgs e)
{
int cid = Convert.ToInt32(this.ddlProvince.SelectedValue.ToString());
this.ddlshi.DataSource = CityManager.GetCityByPid(cid); //获得对应的城市信息
this.ddlshi.DataTextField = "cName";
this.ddlshi.DataValueField = "cID";
this.ddlshi.DataBind();
this.ddlshi.Enabled = true;
this.DropDownList1.Enabled = true;
}
protected void ddlshi_SelectedIndexChanged(object sender, EventArgs e)
{
int cid = Convert.ToInt32(this.ddlshi.SelectedValue.ToString());
this.DropDownList1.DataSource = CountyManager.GetCountyByCityID(cid); //获得对应的区县信息
this.DropDownList1.DataTextField = "cName";
this.DropDownList1.DataValueField = "cID";
this.DropDownList1.DataBind();
}
}
著名 ddlProvince 是省 ddlshi是城市 DropDownList1是区县
现在功能可以实现 但是选择省份后 页面还是刷新 真的不知道为什么 请高人指点
说明白点 或者直接告诉我代码哪错了;;
...全文
相关推荐
使用Ajax时处理用户session失效问题的解决方法
主要为大家详细介绍了使用Ajax时处理用户session失效问题的解决方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
Ajax打开新窗口被浏览器拦截的两种解决办法
最近在做支付时发现打开支付窗口时被浏览器拦截了,怎么回事呢?下面小编给大家分享Ajax打开新窗口被浏览器拦截的两种解决办法,一起看看吧
asp+Ajax简单客户登陆验证
asp+Ajax简单客户登陆验证
AJAX使用了UpdatePanel后无法使用alert弹出脚本
今天在做项目的时候发现个问题。。使用UpdatePanel后alert脚本就要报错了。
使用Ajax时json需要的jar包
jsp页面使用Ajax时获取不到后台所返回的值json的jar包


