首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

Anthem.NET框架实现无刷新的有关问题

2012-11-07 
Anthem.NET框架实现无刷新的问题想实现省、市、地区的DropdownList的无刷三联动,代码如下:%@ Page Language

Anthem.NET框架实现无刷新的问题
想实现省、市、地区的DropdownList的无刷三联动,代码如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="CHEDAI.Web.WebForm2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<%@ Register TagPrefix="anthem" Namespace ="Anthem" Assembly ="Anthem"%>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
  <title>无标题页</title>
</head>
<body>
  <form id="form1" runat="server">
  <div>
  <anthem:DropDownList ID="DropDownList1" runat="server" AutoCallBack="true" 
  onselectedindexchanged="DropDownList1_SelectedIndexChanged"></anthem:DropDownList>
  <anthem:DropDownList ID="DropDownList2" runat="server" AutoCallBack="true"  
  EnabledDuringCallBack="false" 
  onselectedindexchanged="DropDownList2_SelectedIndexChanged"></anthem:DropDownList>
  <anthem:DropDownList ID="DropDownList3" runat="server" AutoCallBack="true" EnabledDuringCallBack="false"></anthem:DropDownList>
  </div>
  </form>
</body>
</html>

后台代码如下:
  protected void Page_Load(object sender, EventArgs e)
  {
  if (!IsPostBack)
  {
  ListItem list = new ListItem();
  list.Text = "--请选择--";
  list.Value = "";
  //进行数据绑定

  DropDownList1.Items.Add(new ListItem("浙江省", "1"));
  DropDownList1.Items.Add(new ListItem("江西省", "2"));
  //在第一个位置添加"--请选择--"
  DropDownList1.Items.Insert(0, list);
  DropDownList2.Items.Insert(0, list);
  DropDownList3.Items.Insert(0, list);
  }

  }

  protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
  {
  ListItem list = new ListItem();
  list.Text = "--请选择--";
  list.Value = "";
  //如果DropDownList1的value值为空,代表没有选择任何的省份.
  if (DropDownList1.SelectedValue != "")
  {
  DropDownList2.Items.Clear();
  DropDownList2.Items.Add(new ListItem("杭州市","1"));
  DropDownList2.Items.Add(new ListItem("宁波市", "1"));
  DropDownList2.Items.Add(new ListItem("嘉兴市", "1"));
  DropDownList2.UpdateAfterCallBack = true;//刷新DropDownList2,这是Anthem组件里面控件的一个属性,单独刷新该控件.
  DropDownList2.Items.Insert(0, list);//为第一个位置添加--请选择--
  }
  else
  {
  DropDownList2.Items.Clear();//清除DropDownList2里面的值.
  DropDownList2.Items.Insert(0, list);
  DropDownList2.UpdateAfterCallBack = true;
  DropDownList3.Items.Clear();
  DropDownList3.Items.Insert(0, list);
  DropDownList3.UpdateAfterCallBack = true;
  }

  }

  protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)


  {
  ListItem list = new ListItem();
  list.Text = "--请选择--";
  list.Value = "";
  if (DropDownList2.SelectedValue != "")
  {
  if(DropDownList2.SelectedItem.Text=="杭州市")
  {
  DropDownList3.Items.Clear();
  DropDownList3.Items.Add(new ListItem("上城区","1"));
  DropDownList3.Items.Add(new ListItem("西湖区", "1"));
  }
  else if (DropDownList2.SelectedItem.Text == "宁波市")
  {
  DropDownList3.Items.Clear();
  DropDownList3.Items.Add(new ListItem("北仑区", "1"));
  DropDownList3.Items.Add(new ListItem("江东区", "1"));
  }
   
  DropDownList3.UpdateAfterCallBack = true;
  DropDownList3.Items.Insert(0, list);
  }
  else
  {
  DropDownList3.Items.Clear();
  DropDownList3.Items.Insert(0, list);
  DropDownList3.UpdateAfterCallBack = true;
  }

  }

问题是DropDownList2下拉列表中选择第一项内容时,DropDownList3内容跟着联动变化;而再次选择DropDownList2列表中其它项时DropDownList3内容没有跟着变化,请有过类似经验的朋友帮忙找找错误,问题有点急,在线等

[解决办法]
参考

省市联动无刷新

热点排行