Dropdownlist 三级联动 无刷新的问题

lxdong8686 2009-06-04 11:13:36

脚本中
<script language="javascript">
//城市------------------------------
function cityResult()
{
var city=document.getElementById("DropDownList1");

Ajax_Method.GetCityList(city.value,CallbackCll);

}

function CallbackCll(response)
{
alert(response.value);

debugger;
document.all("DropDownList2").length=0;    
     var count = response.value.Rows.length;
     alert(count);
if(count !=0)
{
for(var i=0; i<count; i++)
     {
     var name=response.value.Rows[i]["city_name"];
       var id=response.value.Rows[i]["city_id"];
       document.all("DropDownList2").options.add(new Option(name,id));
     }
}


areaResult();
return
}
//市区----------------------------------------
function areaResult()
{
var area=document.getElementById("DropDownList2");
Ajax_Method.GetAreaList(area.value,CallbackCll);
}
function CallbackCll(response)
{
if (response.value != null)
{
document.all("DropDownList3").length=0;    
     var count = response.value.Rows.length;
if(count !=0)
{
for(var i=0; i<count; i++)
     {
       var name=response.value.Rows[i]["qx_name"];;
       var id=response.value.Rows[i]["qx_id"];;
       document.all("DropDownList3").options.add(new Option(name,id));
     }
}
}
return
}
</script>


后台 代码中



public partial class Ajax_Method: System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
AjaxPro.Utility.RegisterTypeForAjax(typeof(Ajax_Method));

if (!IsPostBack)
{
this.DropDownList1.DataSource = GetProvinceList();
this.DropDownList1.DataTextField = "sf_name";
this.DropDownList1.DataValueField = "sf_id";
this.DropDownList1.DataBind();

this.DropDownList1.Attributes.Add("onchange", "cityResult();");
this.DropDownList2.Attributes.Add("onchange", "areaResult();");
}
}

public DataTable GetProvinceList()
{
string sql = "select * from ShengFen";
return Common.getsql(connectionstring_static, sql);
}


[AjaxPro.AjaxMethod]
public static DataTable GetCityList(int provinceid)
{
string sql = "select * from City where sf_id = " + provinceid;
DataTable dt=Common.getsql(connectionstring_static,sql);
return dt;
}

[AjaxPro.AjaxMethod]
public static DataTable GetAreaList(int cityid)
{
string sql = "select * from Qx where City_id = " + cityid;
DataTable dt=Common.getsql(connectionstring_static,sql);
return dt;
}


}

当加载页面的时候只显示 省份的名字 城市 和 区 没有显示 选择某个省份的时候 城市 和 区也不显示




...全文
781 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
hailong20062008 2009-06-04
  • 打赏
  • 举报
回复
如果想无刷新,好像只有js(+ajax)来做了。用asp.net必须控制局部在刷新,用自带的Ajax控件,否则三级联动一般的绑定,选省了,整个页面都会刷新的。
lxdong8686 2009-06-04
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 wuyq11 的回复:]
function CallbackCll(response)
{
if (response.value != null)
{

document.all("DropDownList_province1").length=0; 
document.all("DropDownList_area1").length=0;    
     var ds = response.value;
if(ds != null && typeof(ds) == "object")
{
document.all("DropDownList_province1").options.add(new Option("",""));
for(var i=0; i <ds.Tables[0].Rows.length; i++)
     {

[/Quote]


DropDownList_province1(DropDownList1)已经在后台代码中 绑定数据了为何还要在脚本中添加
银狐被占用 2009-06-04
  • 打赏
  • 举报
回复
回帖是一种美德!每天回帖即可获得 10 分可用分!
wuyq11 2009-06-04
  • 打赏
  • 举报
回复
function CallbackCll(response)
{
if (response.value != null)
{

document.all("DropDownList_province1").length=0; 
document.all("DropDownList_area1").length=0;    
     var ds = response.value;
if(ds != null && typeof(ds) == "object")
{
document.all("DropDownList_province1").options.add(new Option("",""));
for(var i=0; i<ds.Tables[0].Rows.length; i++)
     {
     var name=ds.Tables[0].Rows[i].Province;
       var id=ds.Tables[0].Rows[i].Province;
       document.all("DropDownList_province1").options.add(new Option(name,id));
     }
}
}
return
}
function areaResult()
{
var area=document.getElementById("DropDownList_province1");

var YR=document.getElementById("Hd_province1");
YR.value=area.value;
AjaxMethod.GetCityList(area.value,get_city_Result);
}
function get_city_Result(response)
{
if (response.value != null)
{
document.all("DropDownList_area1").length=0;    
     var ds = response.value;

if(ds != null && typeof(ds) == "object")
{
for(var i=0; i<ds.Tables[0].Rows.length; i++)
     {
       var name=ds.Tables[0].Rows[i].City;
       var id=ds.Tables[0].Rows[i].City;
       document.all("DropDownList_area1").options.add(new Option(name,id));
     }
}
}
return
}
lxdong8686 2009-06-04
  • 打赏
  • 举报
回复
上述问题 如何解决 ....
lxdong8686 2009-06-04
  • 打赏
  • 举报
回复
上述问题 如何解决 ....
lxdong8686 2009-06-04
  • 打赏
  • 举报
回复
上述问题 如何解决 ....
che2piaopiao 2009-06-04
  • 打赏
  • 举报
回复
偶有个js的。。。挺好用

要的话 加 792713666
lxdong8686 2009-06-04
  • 打赏
  • 举报
回复
上述问题 如何解决
lxdong8686 2009-06-04
  • 打赏
  • 举报
回复
数据库

省份 ShengFen 城市 City 区 Qx
sf_id sf_name city_id city_name sf_id qx_id qx_name city_id
dzpzds 2009-06-04
  • 打赏
  • 举报
回复
绑定
uxspy 2009-06-04
  • 打赏
  • 举报
回复
他这个本身就是ajax,没看到[ajax.ajaxmethod]属性吗

1.你用什么浏览器?我看到你的代码里有document.all,比如这个火狐就不支持
2.看看你的浏览器状态烂上有没有js错误?
3.看你的写法跟我以前的写法一样,没什么错误,你可以调试一下,看看返回的table
一方晴空 2009-06-04
  • 打赏
  • 举报
回复
还是js或ajax实现比较好

62,051

社区成员

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

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

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

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