DropDownList 多级联动
语言:VB.net如3个DropDownList:DropDownList1,DropDownList2.DropDownList3aspx中用UpdatePanel总是...
语言:VB.net
如3个 DropDownList :DropDownList 1,DropDownList 2.DropDownList 3
aspx 中用 UpdatePanel 总是提示在“System.Web.UI” 命名空间不明确
AutoPostBack="true",又总会在 DropDownList2.SelectedIndexChanged 执行时一并把DropDownList1.SelectedIndexChanged执行了;
有什么比较简单的方法 展开
如3个 DropDownList :DropDownList 1,DropDownList 2.DropDownList 3
aspx 中用 UpdatePanel 总是提示在“System.Web.UI” 命名空间不明确
AutoPostBack="true",又总会在 DropDownList2.SelectedIndexChanged 执行时一并把DropDownList1.SelectedIndexChanged执行了;
有什么比较简单的方法 展开
展开全部
我才完成了一个选择地址(国家、省份、城市)联动的例子,一下代码你可以参考。
1.联动页面
<script type="text/javascript">
function _ddlChange(obj,index)
{
$.ajax({
type:"get",
url:"Ajaxddl.aspx",
data:"SValue="+obj+"&type="+index,
success:function(msg)
{
var dt=msg.split('|');
for(i = 0;i<dt.length;i++)
{
dt[i]=dt[i].split(',');
}
if(index == 1)
{
var ddlCS = document.getElementById("ddlCountryS");
if(ddlCS.innerHTML.indexOf('选')>0){
ddlCS.options.remove(0);
}
var ddlPS = document.getElementById("ddlProvinceS");
debugger;
ddlPS.options.length=0;
var option=document.createElement('OPTION');
option.text="请选择省份或州";
option.value="0";
ddlPS.options.add(option);
for(i = 0;i<dt.length;i++)
{
var option=document.createElement('OPTION');
option.text=dt[i][1];
option.value=dt[i][0];
ddlPS.options.add(option);
}
}
if(index == 2)
{
var ddlCS = document.getElementById("ddlCountryF");
if(ddlCS.innerHTML.indexOf('选')>0){
ddlCS.options.remove(0);
}
var ddlPS = document.getElementById("ddlProvinceF");
debugger;
ddlPS.options.length=0;
var option=document.createElement('OPTION');
option.text="请选择省份或州";
option.value="0";
ddlPS.options.add(option);
for(i = 0;i<dt.length;i++)
{
var option=document.createElement('OPTION');
option.text=dt[i][1];
option.value=dt[i][0];
ddlPS.options.add(option);
}
}
if(index == 3)
{
var ddlPS = document.getElementById("ddlProvinceS");
if(ddlPS.innerHTML.indexOf('选')>0){
ddlPS.options.remove(0);
}
var hfdPS = document.getElementById("hfdPS");
hfdPS.value = ddlPS.value;
var ddlCTS = document.getElementById("ddlCityS");
ddlCTS.options.length=0;
for(i = 0;i<dt.length;i++)
{
var option=document.createElement('OPTION');
option.text=dt[i][1];
option.value=dt[i][0];
ddlCTS.options.add(option);
}
var hfdCTS = document.getElementById("hfdCTS");
hfdCTS.value = ddlCTS.value;
}
if(index == 4)
{
var ddlPF = document.getElementById("ddlProvinceF");
if(ddlPF.innerHTML.indexOf('选')>0){
ddlPF.options.remove(0);
}
var hfdPF = document.getElementById("hfdPF");
hfdPF.value = ddlPF.value;
var ddlCTF = document.getElementById("ddlCityF");
ddlCTF.options.length=0;
for(i = 0;i<dt.length;i++)
{
var option=document.createElement('OPTION');
option.text=dt[i][1];
option.value=dt[i][0];
ddlCTF.options.add(option);
}
var hfdCTF = document.getElementById("hfdCTF");
hfdCTF.value = ddlCTF.value;
}
}
});
}
</script>
<script type="text/javascript">
//城市改变时
function ddlcity(obj,index)
{
if(index == 5)
{
var hfdCTS = document.getElementById("hfdCTS");
hfdCTS.value = obj;
}
if(index == 6)
{
var hfdCTF = document.getElementById("hfdCTF");
hfdCTF.value = obj;
}
}
</script>
---异步绑定的ddl中的数据无法保存,必须先保存在HiddenField中
<tr>
<td width="30" height="28">
</td>
<td colspan="2" height="28">
国 家:</td>
<td colspan="3" height="28">
<asp:DropDownList runat="server" ID="ddlCountryS" CssClass="a30" onchange="_ddlChange(this.value,1)"></asp:DropDownList>
</td>
<td colspan="5">
</td>
</tr>
<tr>
<td width="30" height="28">
</td>
<td colspan="2" height="28">
省/州:</td>
<td height="28">
<asp:HiddenField runat="server" ID="hfdPS" />
<asp:DropDownList runat="server" ID="ddlProvinceS" CssClass="a31" onchange="_ddlChange(this.value,3)" >
</asp:DropDownList>
</td>
<td height="28">
城 市:</td>
<td height="28">
<asp:HiddenField runat="server" ID="hfdCTS" />
<asp:DropDownList runat="server" ID="ddlCityS" CssClass="a31" onchange="ddlcity(this.value,5)">
</asp:DropDownList>
</td>
<td colspan="5">
</td>
</tr>
2.---Ajaxddl.aspx --改页面不能有多余html标记
--<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Ajaxddl.aspx.cs" Inherits="_51Quick_VIP_Ajaxddl" %>
protected void Page_Load(object sender, EventArgs e)
{
string _SValue = Request.QueryString["SValue"].ToString();
string _SType = Request.QueryString["type"].ToString();
string ret = "";
DataTable dt = new DataTable();
switch (_SType)
{
case "1":
dt = SqlHelper.ExecuteDataSet("select Province,(Pinyin+' '+ProvinceName) as Name from p_Province where Country = " + _SValue).Tables[0];
break;
case "2":
dt = SqlHelper.ExecuteDataSet("select Province,(Pinyin+' '+ProvinceName) as Name from p_Province where Country = " + _SValue).Tables[0];
break;
case "3":
dt = SqlHelper.ExecuteDataSet("select City,(Pinyin+' '+CityName) as Name from p_City where Province = " + _SValue).Tables[0];
break;
case "4":
dt = SqlHelper.ExecuteDataSet("select City,(Pinyin+' '+CityName) as Name from p_City where Province = " + _SValue).Tables[0];
break;
default :
break;
}
if (_SType == "1" || _SType == "2")
{
foreach (DataRow dr in dt.Rows)
{
ret += dr["Province"].ToString() + "," + dr["Name"].ToString() + "|";
}
ret = ret.Substring(0, ret.Length - 1);
}
if (_SType == "3" || _SType == "4")
{
foreach (DataRow dr in dt.Rows)
{
ret += dr["City"].ToString() + "," + dr["Name"].ToString() + "|";
}
ret = ret.Substring(0, ret.Length - 1);
}
Response.Write(ret);
}
1.联动页面
<script type="text/javascript">
function _ddlChange(obj,index)
{
$.ajax({
type:"get",
url:"Ajaxddl.aspx",
data:"SValue="+obj+"&type="+index,
success:function(msg)
{
var dt=msg.split('|');
for(i = 0;i<dt.length;i++)
{
dt[i]=dt[i].split(',');
}
if(index == 1)
{
var ddlCS = document.getElementById("ddlCountryS");
if(ddlCS.innerHTML.indexOf('选')>0){
ddlCS.options.remove(0);
}
var ddlPS = document.getElementById("ddlProvinceS");
debugger;
ddlPS.options.length=0;
var option=document.createElement('OPTION');
option.text="请选择省份或州";
option.value="0";
ddlPS.options.add(option);
for(i = 0;i<dt.length;i++)
{
var option=document.createElement('OPTION');
option.text=dt[i][1];
option.value=dt[i][0];
ddlPS.options.add(option);
}
}
if(index == 2)
{
var ddlCS = document.getElementById("ddlCountryF");
if(ddlCS.innerHTML.indexOf('选')>0){
ddlCS.options.remove(0);
}
var ddlPS = document.getElementById("ddlProvinceF");
debugger;
ddlPS.options.length=0;
var option=document.createElement('OPTION');
option.text="请选择省份或州";
option.value="0";
ddlPS.options.add(option);
for(i = 0;i<dt.length;i++)
{
var option=document.createElement('OPTION');
option.text=dt[i][1];
option.value=dt[i][0];
ddlPS.options.add(option);
}
}
if(index == 3)
{
var ddlPS = document.getElementById("ddlProvinceS");
if(ddlPS.innerHTML.indexOf('选')>0){
ddlPS.options.remove(0);
}
var hfdPS = document.getElementById("hfdPS");
hfdPS.value = ddlPS.value;
var ddlCTS = document.getElementById("ddlCityS");
ddlCTS.options.length=0;
for(i = 0;i<dt.length;i++)
{
var option=document.createElement('OPTION');
option.text=dt[i][1];
option.value=dt[i][0];
ddlCTS.options.add(option);
}
var hfdCTS = document.getElementById("hfdCTS");
hfdCTS.value = ddlCTS.value;
}
if(index == 4)
{
var ddlPF = document.getElementById("ddlProvinceF");
if(ddlPF.innerHTML.indexOf('选')>0){
ddlPF.options.remove(0);
}
var hfdPF = document.getElementById("hfdPF");
hfdPF.value = ddlPF.value;
var ddlCTF = document.getElementById("ddlCityF");
ddlCTF.options.length=0;
for(i = 0;i<dt.length;i++)
{
var option=document.createElement('OPTION');
option.text=dt[i][1];
option.value=dt[i][0];
ddlCTF.options.add(option);
}
var hfdCTF = document.getElementById("hfdCTF");
hfdCTF.value = ddlCTF.value;
}
}
});
}
</script>
<script type="text/javascript">
//城市改变时
function ddlcity(obj,index)
{
if(index == 5)
{
var hfdCTS = document.getElementById("hfdCTS");
hfdCTS.value = obj;
}
if(index == 6)
{
var hfdCTF = document.getElementById("hfdCTF");
hfdCTF.value = obj;
}
}
</script>
---异步绑定的ddl中的数据无法保存,必须先保存在HiddenField中
<tr>
<td width="30" height="28">
</td>
<td colspan="2" height="28">
国 家:</td>
<td colspan="3" height="28">
<asp:DropDownList runat="server" ID="ddlCountryS" CssClass="a30" onchange="_ddlChange(this.value,1)"></asp:DropDownList>
</td>
<td colspan="5">
</td>
</tr>
<tr>
<td width="30" height="28">
</td>
<td colspan="2" height="28">
省/州:</td>
<td height="28">
<asp:HiddenField runat="server" ID="hfdPS" />
<asp:DropDownList runat="server" ID="ddlProvinceS" CssClass="a31" onchange="_ddlChange(this.value,3)" >
</asp:DropDownList>
</td>
<td height="28">
城 市:</td>
<td height="28">
<asp:HiddenField runat="server" ID="hfdCTS" />
<asp:DropDownList runat="server" ID="ddlCityS" CssClass="a31" onchange="ddlcity(this.value,5)">
</asp:DropDownList>
</td>
<td colspan="5">
</td>
</tr>
2.---Ajaxddl.aspx --改页面不能有多余html标记
--<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Ajaxddl.aspx.cs" Inherits="_51Quick_VIP_Ajaxddl" %>
protected void Page_Load(object sender, EventArgs e)
{
string _SValue = Request.QueryString["SValue"].ToString();
string _SType = Request.QueryString["type"].ToString();
string ret = "";
DataTable dt = new DataTable();
switch (_SType)
{
case "1":
dt = SqlHelper.ExecuteDataSet("select Province,(Pinyin+' '+ProvinceName) as Name from p_Province where Country = " + _SValue).Tables[0];
break;
case "2":
dt = SqlHelper.ExecuteDataSet("select Province,(Pinyin+' '+ProvinceName) as Name from p_Province where Country = " + _SValue).Tables[0];
break;
case "3":
dt = SqlHelper.ExecuteDataSet("select City,(Pinyin+' '+CityName) as Name from p_City where Province = " + _SValue).Tables[0];
break;
case "4":
dt = SqlHelper.ExecuteDataSet("select City,(Pinyin+' '+CityName) as Name from p_City where Province = " + _SValue).Tables[0];
break;
default :
break;
}
if (_SType == "1" || _SType == "2")
{
foreach (DataRow dr in dt.Rows)
{
ret += dr["Province"].ToString() + "," + dr["Name"].ToString() + "|";
}
ret = ret.Substring(0, ret.Length - 1);
}
if (_SType == "3" || _SType == "4")
{
foreach (DataRow dr in dt.Rows)
{
ret += dr["City"].ToString() + "," + dr["Name"].ToString() + "|";
}
ret = ret.Substring(0, ret.Length - 1);
}
Response.Write(ret);
}
Storm代理
2023-07-25 广告
2023-07-25 广告
StormProxies是一家可靠的代理服务提供商,提供原生IP(住宅原生IP)和高匿名代理服务。以下是关于StormProxies的原生IP服务的一些信息:1. 住宅原生IP:StormProxies提供的住宅原生IP是指从真实的家庭或企...
点击进入详情页
本回答由Storm代理提供
展开全部
联动一般都应该是阶层的关系,比如说:
List1国家名:中国,美国 选中了中国
List2省名:北京,上海,天津,辽宁…… 比如选中了 辽宁
List3市名:沈阳,大连,鞍山……
当你上层内容选定的时候,他得下层List的内容会相应变更,就是SelectedIndexChanged 事件中处理的应该是他下一层List中的内容,是不会影响到他上一层list。
List1国家名:中国,美国 选中了中国
List2省名:北京,上海,天津,辽宁…… 比如选中了 辽宁
List3市名:沈阳,大连,鞍山……
当你上层内容选定的时候,他得下层List的内容会相应变更,就是SelectedIndexChanged 事件中处理的应该是他下一层List中的内容,是不会影响到他上一层list。
追问
我可能没有讲清楚
list1.SelectedIndexChanged
list2.SelectedIndexChanged
并不是说这两个事件处理有什么问题,而是说只想执行list2.SelectedIndexChanged 时, list1.SelectedIndexChanged 也执行了;(且想AutoPostBack="true" )
有没有什么办法就是两者不互相影响,选择list1就只执行list1.SelectedIndexChanged 里的相关动作。选择list2就只执行list2.SelectedIndexChanged (不用UpdatePanel )
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询