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是区县
现在功能可以实现 但是选择省份后 页面还是刷新 真的不知道为什么 请高人指点
说明白点 或者直接告诉我代码哪错了;;