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

推荐订阅源

L
Lohrmann on Cybersecurity
S
Secure Thoughts
I
Intezer
Forbes - Security
Forbes - Security
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
H
Help Net Security
IT之家
IT之家
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
宝玉的分享
宝玉的分享
S
Securelist
T
The Exploit Database - CXSecurity.com
博客园 - 叶小钗
Security Latest
Security Latest
The Cloudflare Blog
Jina AI
Jina AI
T
Tenable Blog
J
Java Code Geeks
G
GRAHAM CLULEY
C
CERT Recently Published Vulnerability Notes
SecWiki News
SecWiki News
AI
AI
博客园 - 聂微东
S
Schneier on Security
博客园_首页
爱范儿
爱范儿
有赞技术团队
有赞技术团队
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
www.infosecurity-magazine.com
www.infosecurity-magazine.com
博客园 - 【当耐特】
T
Threatpost
Security Archives - TechRepublic
Security Archives - TechRepublic
Help Net Security
Help Net Security
酷 壳 – CoolShell
酷 壳 – CoolShell
Recent Announcements
Recent Announcements
W
WeLiveSecurity
M
MIT News - Artificial intelligence
H
Hackread – Cybersecurity News, Data Breaches, AI and More
月光博客
月光博客
阮一峰的网络日志
阮一峰的网络日志
Last Week in AI
Last Week in AI
T
Threat Research - Cisco Blogs
S
Security Affairs
T
Tor Project blog
T
Tailwind CSS Blog
N
News | PayPal Newsroom
C
CXSECURITY Database RSS Feed - CXSecurity.com
云风的 BLOG
云风的 BLOG
P
Proofpoint News Feed
The Register - Security
The Register - Security
D
Darknet – Hacking Tools, Hacker News & Cyber Security

博客园 - BlackAngel2bAssassin

使用SQL SERVER 内部函数进行密码加密和校验小问题 还原MOSS 默认的权限级别 破译moss 2007 中的权限提升功能 后台代码中使用Post 进行跳转 在自定义HttpHandler 中使用Session asp.net 1.1 用户控件的第二种重用 一个DataGrid 的CheckBoxColumn FireBird 点滴之JDBC连接字串 (转贴)使用Repeater实现自定义多列数据绑定 - BlackAngel2bAssassin - 博客园 (转贴)使用PagedDataSource给Repeater、DataList增加分页 (转贴)给Repeater、Datalist和Datagrid增加自动编号列 (转贴)如何取得DataGrid绑定列和模板列中的值 重新理解.net remoting SPS 中修改用户密码的WebPart 工程 FireBird 的使用点滴(一) 使用Webpart包装ActiveX组件 制作用户修改密码Webpart 的简短步骤 一个忘却了的SharePoint 的Bug 抽取word、excel、pdf等文件[转载]
(转贴)实现带有数据绑定的客户端脚本控制的二级联动菜单
BlackAngel2bAssassin · 2005-08-22 · via 博客园 - BlackAngel2bAssassin

今天制作了一个客户端javascript脚本控制的二级联动菜单,使用ASP.NET很容易就能制作联动菜单,但是有个很大的问题,就是当选择一级菜单时,由于ASP.NET本身的特性,选择的项目需要被提交到服务器处理,然后再返回二级菜单的内容,中间有个服务器往返的问题,同时造成页面刷新,这在网络状况不好的情况下很不利。

我个人感觉使用客户端javascript脚本控制,难点是两个菜单中的数据都是数据库中动态绑定上去的,因此如何将菜单中的数据读入到客户点脚本中也是一个问题。可以使用ASP.NET动态生成含有菜单的元素内容的script脚本,这样在客户端进行菜单选择时,全部都是客户端脚本操作,速度很快,从而提高了性能。

以下举一个例子,一级菜单显示的栏目的类别(Catalogs),每个类别下又下设了很多的栏目(Class),因此二级菜单的内容就是根据一级菜单栏目的选择显示出栏目。首先先介绍一下用到的数据表:

 

  newscatalogs表

newsclass表

PK

catalogid

classid

catalogname

classname

foundname

catalogid

addTime

addtime

在VS中新建一个webform,页面上放置两个下拉列表框DropDownlist服务器控件,一个ID是ddlcatalogs,一个ID是ddlclasses,然后再放置一个TextBox,ID是classid,注意三个控件都要在<form></form>标记内。每次在ddlcatalogs中选择一个类别,在ddlclasses中会自动生成属于此类别下的所有栏目,选择ddlclasses中的栏目,会在classid中显示出所选择栏目的数据库id。

控件的HTML代码如下:


在页面的Page_Load事件中输入以下代码(代码是用VB.NET写的,读者如使用C#可以理解原理后自己改写):

运行一下,在浏览中选择查看源代码,即可看见程序生成的含有数据的script(模拟数据):

 1<script><!--
 2var group=new Array(5);for (i=0; i<5; i++){group[i] = new Array()}
 3group[0][0]=new Option("学院公共信息","23");
 4group[0][1]=new Option("学院公报","24");
 5group[1][0]=new Option("首页新闻","10");
 6group[1][1]=new Option("首页公告","11");
 7group[2][0]=new Option("营销快讯","12");
 8group[2][1]=new Option("营销系-教学论文","13");
 9group[2][2]=new Option("网络营销快讯","17");
10group[2][3]=new Option("就业信息","20");
11group[3][0]=new Option("秘书室新闻","21");
12group[4][0]=new Option("IT技术","18");
13group[4][1]=new Option(".net技术","19");
14
15function redirect(x){
16for (m=Form1.l1.options.length-1;m>0;m--){Form1.l1.options[m]=null}
17for (i=0;i<group[x].length;i++){
18Form1.l1.options[i]=new Option(group[x][i].text,group[x][i].value)}
19Form1.l1.options[0].selected=true;Form1.classid.value=Form1.l1.options[0].value;}
20function choose(x){Form1.classid.value=Form1.l1.options[x].value;}
21--></script>