AJAX的问题.请高手们来看看!

dingbaoliang 2008-11-06 05:01:43
我做了一个三级联动
前台

<%@ 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是区县

现在功能可以实现 但是选择省份后 页面还是刷新 真的不知道为什么 请高人指点

说明白点 或者直接告诉我代码哪错了;;
...全文
112 16 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
dingbaoliang 2008-11-07
  • 打赏
  • 举报
回复
UpdateMode
表示UpdatePanel的更新模式,有两个选项:Always和Conditional。Always是不管有没有Trigger,其他控件都将更新该UpdatePanel,Conditional表示只有当前UpdatePanel的Trigger,或ChildrenAsTriggers属性为true时当前UpdatePanel中控件引发的异步回送或者整页回送,或是服务器端调用Update()方法才会引发更新该UpdatePanel。


我的ChildrenAsTriggers为True 怎么也不行啊 哎呀

lfywy 2008-11-07
  • 打赏
  • 举报
回复
这个没怎么用过,关注
zlb789 2008-11-07
  • 打赏
  • 举报
回复
up
dingbaoliang 2008-11-07
  • 打赏
  • 举报
回复
加了这段也不好使

</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddlProvince" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>


这个<Triggers>是什么意思啊?
lizhimin0310 2008-11-06
  • 打赏
  • 举报
回复
d
mjjzg 2008-11-06
  • 打赏
  • 举报
回复
没这样搞过,顶一下,以表支持
  • 打赏
  • 举报
回复
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
风骑士之怒 2008-11-06
  • 打赏
  • 举报
回复
UP,顺便提一个:

利用AJAX Control ToolKit控件集里面的CascadingDropDown控件可以实现,

CascadingDropDown控件 类型:具有AJAX功能的Extender控件

功能:提供一组联动式的DropDownList,可在不Postback的状况下,通过WEB services动态从Server端(数据库中)获取DropDownList内的Item。

使用时机:在页面上呈现出分类选项,例如工厂、部门等多层次数据,item数众多,想通过多个DropDownList分类,但又不想换页(postback)时使用
seeupseeup 2008-11-06
  • 打赏
  • 举报
回复
UP
zhengxy22 2008-11-06
  • 打赏
  • 举报
回复
up
takako_mu 2008-11-06
  • 打赏
  • 举报
回复
像這樣寫

</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
lovehongyun 2008-11-06
  • 打赏
  • 举报
回复
没用过asp.net ajax这个框架.
帮up

lilihua520 2008-11-06
  • 打赏
  • 举报
回复
up
takako_mu 2008-11-06
  • 打赏
  • 举报
回复
你少Trigger觸發。。。。
</ContentTemplate>
</asp:UpdatePanel>
qinhl99 2008-11-06
  • 打赏
  • 举报
回复
up
firev000 2008-11-06
  • 打赏
  • 举报
回复
<updatepanel>里面的<trigger>里面把 OnSelectedIndexChanged 添加进去

62,243

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧