asp.net中的htmlcontrol控件select的选择事件

trainli 2006-08-31 05:02:55
在<form action="a.aspx">里有两个<select id=1 runat="server"><select id=2 runat="server">
当我选择第一个的时候改变第二个select的值,我在.cs里写了第一个select的一个事件怎么就是不通知改变呢?如我这样写:
private void flh_ServerChange(object sender, System.EventArgs e)
{
Response.write("dlkf");
}
<SELECT id="1" onserverchange="flh_ServerChange" name="1" runat="server"></SELECT>

请问这样对吗?我用onchange也不可以,onclick也不可以!不知道这样要怎么去写!
...全文
1035 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
trainli 2006-08-31
  • 打赏
  • 举报
回复
好长呀!有没有简单一点的写两个就可以了
xddouble 2006-08-31
  • 打赏
  • 举报
回复

function change(coid){
location.assign("three.asp?action=s_s&cid=<%=cid%>&coid=" + coid);
}
-->
</script>
cctaiyang 2006-08-31
  • 打赏
  • 举报
回复
楼主不好意思,以前做的例子找不到了,给你贴点代码吧,抱歉,不过道理一样都是多级联动

<html>
<head>
<title>js动态三级联动下拉表单试验</title>
<!--=======打开数据库======-->
<%
Set Conn = Server.CreateObject("ADODB.Connection")
StrCnn = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("db1.mdb") & ";"
Conn.Open StrCnn
%>
</head>
<body>
<form name="myform" method="post">
<%
set rs=server.CreateObject("adodb.recordset")
sq="select * from 一级表"
rs.open sq,conn,1,1
%>
<select name="class1" onChange="changeclass2();changeclass3()">
<option value="" selected>选择一级目录</option>
<%
while not rs.eof
%>
<option value="<%=rs("一级类")%>"><%=rs("一级类")
%>
</option>
<%
rs.movenext
wend
rs.close
%>
</select>
<select name="class2" onChange="changeclass3()">
<option value="" selected>选择二级目录</option>
</select>
<select name="class3">
<option value="" selected>选择三级目录</option>
</select>
<%
sql="select * from 二级表"
rs.open sql,conn,1,1
num=rs.recordcount
str=""
for i=1 to rs.recordcount
str=str&rs("一级类")&"-"&rs("二级类")&","
if rs.eof then exit for
rs.movenext
next
rs.close
%>
<%
sql="select * from 三级表"
rs.open sql,conn,1,1
num2=rs.recordcount
str2=""
for i=1 to rs.recordcount
str2=str2&rs("二级类")&"-"&rs("三级类")&","
if rs.eof then exit for
rs.movenext
next
rs.close
%>
<!--下面是实现动态改变下一级菜单的脚本代码-->
<script LANGUAGE="javascript">
arr="<%=str%>".split(",");
a=arr.length
ar=new Array()
for (i=0;i<a;i++){
ar[i]=arr[i].split("-");
}
onecount=ar.length;
arr2="<%=str2%>".split(",");
a2=arr2.length
ar2=new Array()
for (i=0;i<a2;i++){
ar2[i]=arr2[i].split("-");
}
onecount2=ar2.length;
function changeclass2() {
document.myform.class2.length=0
lid=myform.class1.value;
for (i=0;i<onecount;i++) {
if (ar[i][0] == lid) {
document.myform.class2.options.add(new Option(ar[i][1], ar[i][1]));
}
}
}
function changeclass3() {
document.myform.class3.length=0
lid2=myform.class2.value;
for (i=0;i<onecount2;i++) {
if (ar2[i][0] == lid2) {
document.myform.class3.options.add(new Option(ar2[i][1], ar2[i][1]));
}
}
}
</script>
</body>
</html>




Reqeust获取参数实现动态三级联动下拉表单

<!--#include file="conn.asp"-->
<%
dim cid,coid
cid = request("cid") 'cid 大类id
coid = request("coid") 'coid 中类id
set rs=server.createobject("adodb.recordset")
sql = "select * from edu_c" '表一 大类表
rs.open sql,conn,1,1
strOption1 = "<option value='' selected >==请选择所属市局==</option>"
do while not rs.eof
if cstr(rs("id")) = cstr(cid) then
strOption1 = strOption1 & "<option value='" & rs("id") & "' selected>" & rs("c_name") & "</option>"
else

strOption1 = strOption1 & "<option value='" & rs("id") & "'>" & rs("c_name") & "</option>"

end if
rs.movenext
loop

rs.close

if cid <> "" then
sql = "select * from edu_co where c_id=" & cid '表二 中类表 bid==表一中的id

rs.open sql,conn,1,1
strOption2 = "<option value='' selected >==请选择所属县局==</option>"

do while not rs.eof
if cstr(rs("id")) = cstr(coid) then
strOption2 = strOption2 & "<option value='" & rs("id") & "' selected>" & rs("co_name") & "</option>"
else
strOption2 = strOption2 & "<option value='" & rs("id") & "'>" & rs("co_name") & "</option>"
end if
rs.movenext
loop
rs.close
end if

if coid <> "" then
sql = "select * from edu_s where co_id= " & coid '表三 小类表 mid==表二的id
rs.open sql,conn,1,1
strOption3 = "<option value='' selected >==请选择学校==</option>"
while not rs.eof
if cstr(rs("id")) = cstr(sid) then
strOption3 = strOption3 & "<option value='" & rs("id") & "' selected>" & rs("s_name") & "</option>"
else
strOption3 = strOption3 & "<option value='" & rs("id") & "'>" & rs("s_name") & "</option>"
end if

rs.movenext
wend
rs.close
end if

%>
<select onchange="changeb(this.value)" name="cid"><%=strOption1%></select>
<select onchange="change(this.value)" name="coid"><%=strOption2%></select>
<select name="sid"><%=strOption3%></select>
<script language="javascript">
<!--
function changeb(cid){
location.assign("three.asp?action=s_s&cid=" + cid);
}

function change(coid){
location.assign("three.asp?action=s_s&cid=<%=cid%>&coid=" + coid);
}
-->
</script>
cctaiyang 2006-08-31
  • 打赏
  • 举报
回复

<script language="javascript" type="text/javascript">
<!--

function Select1_onchange() {
Select2.selectedIndex = 3;

}

// -->
</script>
<select id="Select1" language="javascript" onchange="return Select1_onchange()">
<option selected="selected">a1</option>
<option>a2</option>
<option>a3</option>
</select>
<select id="Select2">
<option selected="selected">a11</option>
<option>a12</option>
<option>a13</option>
<option>a21</option>
</select>
trainli 2006-08-31
  • 打赏
  • 举报
回复
this.Select1.ServerChange += new System.EventHandler(this.flh_ServerChange);
这个已经写上了呀



可以用JS实现联动效果嘛,也可以用js来提交你做的操作;<select id=1 runat="server" onchange="document.submit();">

但这样会把整个页面提交了,我是不能把页面提交
trainli 2006-08-31
  • 打赏
  • 举报
回复
asi225@163.com
zorou_fatal 2006-08-31
  • 打赏
  • 举报
回复
如果你要申明你的htmlcontrol的onserverchange事件
必须在你的cs里写对它的事件的委托

this.Select1.ServerChange += new System.EventHandler(this.flh_ServerChange);

否则是不会触发的
yuchangmao 2006-08-31
  • 打赏
  • 举报
回复
可以用JS实现联动效果嘛,也可以用js来提交你做的操作;<select id=1 runat="server" onchange="document.submit();">
卧_槽 2006-08-31
  • 打赏
  • 举报
回复
htmlcontrol要能够post网页数据回服务器段才能用cs代码处理。
还是先学习好html协议吧
cctaiyang 2006-08-31
  • 打赏
  • 举报
回复
我有,给我你的mail
trainli 2006-08-31
  • 打赏
  • 举报
回复
如果我现在不用dropdownlist呢???我就想用htmlcontrol请问有没有 好的方法和例子???和代码??
德仔 2006-08-31
  • 打赏
  • 举报
回复
改用DropDownList,设置为AutoPostback="true"
在cs里面,对其属性定义
Small__Wolf 2006-08-31
  • 打赏
  • 举报
回复
AutoPostback="true"
Crazy__Bear 2006-08-31
  • 打赏
  • 举报
回复
改用DropDownList,设置为AutoPostback="true"

62,041

社区成员

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

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

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

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