惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V2EX - 技术
V2EX - 技术
博客园 - Franky
The GitHub Blog
The GitHub Blog
Y
Y Combinator Blog
MongoDB | Blog
MongoDB | Blog
C
Check Point Blog
P
Proofpoint News Feed
雷峰网
雷峰网
F
Fortinet All Blogs
酷 壳 – CoolShell
酷 壳 – CoolShell
I
InfoQ
H
Help Net Security
T
Tailwind CSS Blog
博客园 - 聂微东
博客园 - 【当耐特】
S
Schneier on Security
The Hacker News
The Hacker News
I
Intezer
博客园 - 三生石上(FineUI控件)
量子位
AWS News Blog
AWS News Blog
T
The Exploit Database - CXSecurity.com
腾讯CDC
Hugging Face - Blog
Hugging Face - Blog
P
Palo Alto Networks Blog
P
Privacy International News Feed
V
Vulnerabilities – Threatpost
NISL@THU
NISL@THU
宝玉的分享
宝玉的分享
Cyberwarzone
Cyberwarzone
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
T
Threat Research - Cisco Blogs
Microsoft Azure Blog
Microsoft Azure Blog
B
Blog
T
The Blog of Author Tim Ferriss
Security Latest
Security Latest
H
Hacker News: Front Page
Vercel News
Vercel News
A
Arctic Wolf
L
LINUX DO - 热门话题
G
GRAHAM CLULEY
Simon Willison's Weblog
Simon Willison's Weblog
Google Online Security Blog
Google Online Security Blog
W
WeLiveSecurity
Scott Helme
Scott Helme
Hacker News - Newest:
Hacker News - Newest: "LLM"
O
OpenAI News
TaoSecurity Blog
TaoSecurity Blog
Jina AI
Jina AI
爱范儿
爱范儿

博客园 - 冷火

Lucene.Net学习 Argotic Syndication Framework生成RSS - 冷火 Confirm GridView Deletes with the ModalPopupExtender 如何在C#中实现图片缩放 [ASP.NET] 限制上传文件类型的两种方法 asp.net采集 在C#怎用一条正则表达式验证用逗号隔开的email地址 关于LumiSoft.Net.POP3.Client接收邮件例子(包括附件) dhtmlXTreeprofessional asp.net导出xml文件 - 冷火 - 博客园 DateDiff Datagridview下一行下一行 GridView控件修改、删除示例(修改含有DropDownList控件) - 冷火 - 博客园 局域网QQ第三版(V1.4) 非常好的菜单效果(Accordion风格) 静功解决失眠的问题 ASP.NET中文验证码详解 log4net Config Examples 对XAML进行编辑的辅助类(XamlHelper)
asp.net+JSON+AJAX(基于prototype1.4)做无刷新的2级DropDownList - 冷火 - 博客园
冷火 · 2008-10-18 · via 博客园 - 冷火

JSON的数据格式:{"xx":"xx1","yy":[{"yy1":"yyy1"},{"yy2":"yyy2"}]}

后台部分:(合成JSON数据格式)

//这是获取根目录
public string getRootTree()
{

using(SqlDataReader dr=SqlHelper.ExecuteReader(conn,System.Data.CommandType.Text,"select * from MMenu where MParentID=0"))
{
sb.Append("{""region"":[");
while(dr.Read())
{
sb.Append("{""");
sb.Append("MID");
sb.Append(""":""");
sb.Append(dr["MID"].ToString());
sb.Append(""",""");
sb.Append("MName");
sb.Append(""":""");
sb.Append(dr["MName"].ToString());
sb.Append(""",""");
sb.Append("MParentID");
sb.Append(""":""");
sb.Append(dr["MParentID"].ToString());
sb.Append("""},");
}
sb.Append("]");
return sb.ToString().Substring(0,sb.ToString().Length-2)+"]}";
}

//根据ID获取下级的数据

public string getSubTree(int MID)
{
using(SqlDataReader dr=SqlHelper.ExecuteReader(conn,System.Data.CommandType.Text,"select * from MMenu where MParentID="+MID))
{
sb.Append("{""region"":[");
while(dr.Read())
{
sb.Append("{""");
sb.Append("MID");
sb.Append(""":""");
sb.Append(dr["MID"].ToString());
sb.Append(""",""");
sb.Append("MName");
sb.Append(""":""");
sb.Append(dr["MName"].ToString());
sb.Append(""",""");
sb.Append("MParentID");
sb.Append(""":""");
sb.Append(dr["MParentID"].ToString());
sb.Append("""},");
}
sb.Append("]");
return sb.ToString().Substring(0,sb.ToString().Length-2)+"]}";
}
}

前台部分:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >

<html>
<head>
<title>select</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name=vs_defaultClientScript content="JavaScript">
<meta name=vs_targetSchema content="http://schemas.microsoft.com/intellisense/ie5">
<script src=js/prototype-1.4.0.js></script>
<script>
function getJSON()
{
var myoptions={
parameters:"",
method:"get",
onSuccess:function(res){
var myData=eval("("+res.responseText+")");
myData.region.each(function(xx){
$("root").options.add(new Option(xx.MName,xx.MID));
}
);

}
}
new Ajax.Request("jsonSelect.aspx?action=root&s"+Math.random(),myoptions);
}

function getSub(id)
{
var myoptions={
parameters:"subID="+id,
method:"get",
onSuccess:function(res){
var myData=eval("("+res.responseText+")");
$("sub").options.length=1;
myData.region.each(function(xx){

$("sub").options.add(new Option(xx.MName,xx.MID));
}
);
}
}
new Ajax.Request("jsonSelect.aspx?action=sub&s"+Math.random(),myoptions);
}
</script>
</head>
<body onload=getJSON()>

<form id="Form1" method="post" runat="server">
<select name="a" id="root" onChange="getSub(this.value)">
<option value="" selected>-----请选择类别-----</option>

</select>
<select name="a" id="sub" onChange="getSub(this.value)">
<option value="" selected>-----请选择类别-----</option>

</select>
</form>

</body>
</html>