第二电脑网导读:p; 数据库为国家统计局最新的行政区划,自己又加入了香港、台湾、澳门的行政区划,需要的朋友可直接下载使用。 数据库下载 /Files/netshuai/area.rar aspx页面代码 <% =strAreaData %> <script language = "J...
正文:此为DropDownList无刷新三级联动的另一种方法,使用JavaScript操作,因是在客户端操作,所以切换速度较快,但如果数据量大时,加载时会稍慢点,下一篇文章我会发布针对此方法的改进方案,供大家参考。此为DropDownList示例,ListBox只需略加修改。 数据库为国家统计局最新的行政区划,自己又加入了香港、台湾、澳门的行政区划,需要的朋友可直接下载使用。
数据库下载
/Files/netshuai/area.rar
ASP/ target=_blank class=infotextkey>aspx页面代码
<% =strAreaData %>
<script language = "JavaScript" type="text/javascript">
function changearea1()
{
document.all("<% =Ddl_AreaTwo.ClientID %>").length = 0;
document.all("<% =Ddl_AreaTwo.ClientID %>").options[0] = new Option('选择城市','0');
document.all("<% =Ddl_AreaThree.ClientID %>").length = 0;
document.all("<% =Ddl_AreaThree.ClientID %>").options[0] = new Option('选择城市','0');
var oneid=document.all("<% =Ddl_AreaOne.ClientID %>").value;
var i;
for (i=0;i < onecount; i++)
{
if (subcat[i][1] == oneid)
{
document.all("<% =Ddl_AreaTwo.ClientID %>").options[document.all("<% =Ddl_AreaTwo.ClientID %>").length] = new Option(subcat[i][0], subcat[i][2]);
}
}
}
function changearea2()
{
document.all("<% =Ddl_AreaThree.ClientID %>").length = 0;
document.all("<% =Ddl_AreaThree.ClientID %>").options[0] = new Option('选择城市','0');
var twoid=document.all("<% =Ddl_AreaTwo.ClientID %>").value;
var oneid=document.all("<% =Ddl_AreaOne.ClientID %>").value;
var i;
for (i=0;i < onecount1; i++)
{
if (subcat1[i][2] == twoid)
{
if (subcat1[i][1] == oneid)
{
document.all("<% =Ddl_AreaThree.ClientID %>").options[document.all("<% =Ddl_AreaThree.ClientID %>").length] = new Option(subcat1[i][0], subcat1[i][3]);
}
}
}
}
</script>
<asp:DropDownList ID="Ddl_AreaOne" runat="server" AppendDataBoundItems="True">
<asp:ListItem Value="0">请选择</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="Ddl_AreaTwo" runat="server" >
<asp:ListItem Value="0">请选择</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="Ddl_AreaThree" runat="server" >
<asp:ListItem Value="0">请选择</asp:ListItem>
</asp:DropDownList>
cs页面代码
protected string strAreaData;
protected void Page_Load(object sender, EventArgs e)
{
Ddl_AreaOne.Attributes.Add("onchange", "changearea1()");
Ddl_AreaTwo.Attributes.Add("onchange", "changearea2()");
string strSQL;
strSQL = "select * from nts_area where oneid<>0 and twoid=0 and threeid=0 order by sort";
《asp.net实现DropDownList、ListBox无刷新三级联动(javascrip)》由第二电脑网原创提供,转载请注明:http://www.002pc.com/master/College/Programming/aspnet/13267.html
关键字:
关于《asp.net实现DropDownList、ListBox无刷新三级联动(javascrip)》文章的评论