兰色精灵 发表于 2015-2-3 23:32:21

ASP网站制作之创立静态下拉式选单(三阶级)

SQL Server是基于服务器端的中型的数据库,可以适合大容量数据的应用,在功能上管理上也要比Access要强得多。在处理海量数据的效率,后台开发的灵活性,可扩展性等方面强大。   '创立B下拉式x (三A)

<%'将材料库保持字串, SQL 叙说,构成第一个表单字串变数 (colorlist),第一个表单称号 'color,构成第二个表单字串变数 (fruitlist),第二一个表单称号 fruit,构成第三个表单字串变数 '(pricelist),第三个表单称号 price,等新闻透过呼唤副程式的体例经由处置以后再传回主程式'中,请注重有某几个参数是以 ByRef 的体例传回主程式,而某些参数是以 ByVal 的体例传回'的紫色粗体字代表是 ByRef。请直接旁观底下副程式的局部
myDSN="Provider=SQLOLEDB; Data Source=Jackal; Initial Catalog=pubs; User ID=sa; Password="
strSQL="select color.color, fruit.fruit, price.cost from color join fruit on color.ID=fruit.COLORID join price on price.FRUITID=fruit.ID order by color.ID"
call listmaker(myDSN, strSQL, colorlist,"color", fruitlist ,"fruit", pricelist, "price", pubevent, pubfun, "myForm")%><form name="myForm" method=post action=listbox2.asp>
色彩:
<%= colorlist%>

<BR>
生果:


<%= fruitlist%>

<BR>
价钱:
<%= pricelist%>
<input type=submit value="送出">
</Form>
<SCRIPT Language="JavaScript"><!--

<%=pubevent%>
<%=pubfun%>
--></Script>


<%

SUB listmaker(myDSN, strSQL,byref list1, listname1, byref list2, listname2, byref list3, listname3, byref myevent, byref myfun, myForm)
Set my_conn = Server.CreateObject("ADODB.Connection")
my_conn.open myDSN
set rs=my_conn.execute(strSQL)
'使用 colorlist 字串变数来创立第一个下拉式选单的 Html 原始码。
colorlist="<select name=" & listname1
colorlist=colorlist & " OnChange=""Buildkey"
colorlist=colorlist & "(this.selectedIndex);"">"
'使用 fruitlist 字串变数来创立第二个下拉式选单的 Html 原始码。
fruitlist="<select name=" & listname2
fruitlist=fruitlist & " OnChange=""Buildkey1"
fruitlist=fruitlist & "(this.selectedIndex);"">"
'使用 pricelist 字串变数来创立第三个下拉式选单的 Html 原始码。
pricelist="<select name=" & listname3 & ">"
'在这里初始某些变数值,看成底下履行运算时之旗标值。
loopcounter=0
lastvalue=rs(0)
lastvalue2=rs(1)
redim tempArray(1)
'thisgroupcount 代表某种色彩共有几种生果
thisgroupcount=0
'thissubgroupcount 代表某种生果共有几种价钱,当生果变换时 thissubgroupcount会归零,偏重新'累加。
thissubgroupcount=0
'howmanygroups 代表共有几种色彩
howmanygroups=0
'howmanysubgroups 代表共有几种生果,当色彩变换时 howmanysubgroups 会归零,偏重新'累加。
howmanysubgroups=0
DO UNTIL rs.eof
thisvalue=rs(0)
thisvalue2=rs(1)
thisvalue3=rs(2)

'假如发明生果称号改动,并且今朝生果是某种色彩的第一种生果时,比如:白色←苹果 '或:黄色←柳丁时就在 Script 中加上色彩标志 (为了让人人更轻易将 Script 区离隔'来),然后再将生果称号界说到 key 阵列值,
'接着再界说 key1[第几种色彩][第几种生果] 之阵列长度。

if thisvalue2<>lastvalue2 then
If howmanysubgroups=0 then
tempSTR1=tempSTR1 & "// " & lastvalue & vbcrlf
tempSTR2=tempSTR2 & "// " & lastvalue & vbcrlf
end If
tempSTR2=tempSTR2 & "key1[" & howmanygroups & "][" & howmanysubgroups &
"]=new Array(" & thissubgroupcount & ");" & vbcrlf
tempSTR1=tempSTR1 & "key[" & howmanygroups & "][" & howmanysubgroups &
"]=""" & lastvalue2 & """;" & vbCRLF
howmanysubgroups=howmanysubgroups+1
thissubgroupcount=0
lastvalue2=thisvalue2
end if
'履行了局以下
// 白色
key="苹果";
key="莲雾";
key="李子";
// 黄色
key="柳丁";
key="葡萄柚";
// 绿色
key="芭乐";
key="西瓜";
key="枣子";
// 白色
key1=new Array(3);
key1=new Array(3);
key1=new Array(3);
// 黄色
key1=new Array(3);
key1=new Array(3);
// 绿色
key1=new Array(3);
key1=new Array(3);
key1=new Array(3);

'假如发明色彩称号改动,就界说 key[第几种色彩] 阵列值,
'接着再界说 key1[第几种色彩] 之阵列长度,反复界说的缘由在之前已跟人人说过了,然'后将howmanygroups (色彩品种) 值加一,并将生果品种计数值 (thisgroupcount) 归零if thisvalue<>lastvalue then
tempSTR=tempSTR & "key[" & howmanygroups & "]=new Array(" & howmanysubgroups & ");" & _vbcrlf
tempSTR=tempSTR & "key1[" & howmanygroups & "]=new Array(" & howmanysubgroups & ");" & _vbcrlf
thisgroupcount=0
howmanygroups=howmanygroups+1
howmanysubgroups=0
end if

'履行了局以下
key=new Array(3);
key1=new Array(3);
key=new Array(3);
key1=new Array(3);
key=new Array(2);
key1=new Array(2);
key=new Array(3);
key1=new Array(3)
'假如 thisgroupcount=0 代表今朝色彩改动,此时将色彩称号写到 color 下拉式选单中if thisgroupcount=0 then
colorlist =colorlist & "<option>" & thisvalue & "</option>" & vbcrlf
end if
'假如 thissubgroupcount=0 代表今朝生果改动,此时在key1[第几种色彩][第几种生果][第几'种价钱] 阵列值前加下水果称号标志,让人人更轻易将生果称号与价钱区离隔来。
if thissubgroupcount=0 then
tempSTR3=tempSTR3 & "// " & lastvalue2 & vbcrlf
end if
'界说key1[第几种色彩][第几种生果][第几种价钱] 阵列值。
tempSTR3=TempSTR3 & "key1[" & howmanygroups & "][" & howmanysubgroups & "][" & thissubgroupcount & "]=""" & thisvalue3 & """;" & vbCRLF '履行了局:
// 频果
key1="10元";
key1="20元";
key1="30元";
// 莲雾
key1="40元";
key1="50元";
key1="60元";
// 李子
key1="70元";
key1="80元";
key1="90元";
// 柳丁
key1="100元";
key1="110元";
key1="120元";
// 葡萄柚
key1="130元";
key1="140元";
key1="150元";
// 芭乐
key1="160元";
key1="170元";
key1="180元";
// 西瓜
key1="190元";
key1="200元";
key1="210元";
// 枣子
key1="220元";
key1="230元";
key1="240元";

'假如今朝是第一种色彩,并且生果称号正在改动,就将生果称号写到 fruit 下拉式选单中 if howmanygroups=0 then
If thissubgroupcount=0 then
fruitlist = fruitlist & "<option>" & thisvalue2 & "</option>" & vbcrlf
end if
End If

'假如今朝是第一种色彩,并且是第一种生果,就将价钱写到 price 下拉式选单。
if howmanygroups=0 then
if howmanysubgroups=0 then
pricelist = pricelist & "<option>" & thisvalue3 & "</option>" & vbcrlf
end if
End if

thisgroupcount=thisgroupcount+1
thissubgroupcount=thissubgroupcount+1
lastvalue=thisvalue
loopcounter=loopcounter+1
rs.movenext

LOOP
'别忘了最初一个 key[第几种色彩] 和 key1[第几种色彩] 的阵列长度还不决义。
tempSTR=tempSTR & "key[" & howmanygroups & _
"]=new Array(" & howmanysubgroups+1 & ");" & _
vbcrlf
tempSTR=tempSTR & "key1[" & howmanygroups & _
"]=new Array(" & howmanysubgroups+1 & ");" & _
vbcrlf

'别忘了最初一个 key[第几种色彩][第几种生果] 和 key1[第几种色彩][第几种生果] 的阵列长'度还不决义。
tempSTR2=TempSTR2 &"key1[" & howmanygroups & "][" & howmanysubgroups & "]=new Array(" & thissubgroupcount & ");" & _vbcrlf
tempSTR1= TempSTR1 & "key[" & howmanygroups & "][" & howmanysubgroups & "]=""" & lastvalue2 & """;" & vbCRLF tempSTR=tempSTR & TempSTR1 & TempSTR2 & tempSTR3
'将 color 下拉式选单作一个开头
colorlist=colorlist & "</select>"
'将 fruit 下拉式选单作一个开头
fruitlist= fruitlist & "</select>"
'将 price 下拉式选单作一个开头
pricelist= pricelist & "</select>"

'一入手下手的 key 和 key1 阵列也不要健忘界说了。

myevent=vbcrlf & "key=new Array(" & howmanygroups+1 & ");"
myevent=myevent & vbcrlf & "key1=new Array(" & howmanygroups+1
myevent=myevent & ");" & vbcrlf & tempSTR

'半途而废,可以封闭材料库了。
rs.close
set rs=nothing
my_conn.close
set my_conn=nothing

'先发生 Buildkey 副程式,这边一点都不坚苦,道理在下面已注释过了,笔者不再赘述,履行了局为:
function Buildkey(num)
{
Buildkey1(0);
document.myForm.fruit.selectedIndex=0;
for(ctr=0;ctr<key.length;ctr++)
{
document.myForm.fruit.options=new Option(key,key);
}
document.myForm.fruit.length=key.length;
}

tempSTR =vbcrlf & "function Buildkey" & "(num)" & vbcrlf
tempSTR =tempSTR & "{" & vbcrlf
tempSTR =tempSTR & "Buildkey1(0);" & vbcrlf
tempSTR =tempSTR & "document." & myForm & "."
tempSTR =tempSTR & listname2 & ".selectedIndex=0;" & vbcrlf
tempSTR =tempSTR & "for(ctr=0;ctr<key.length;ctr++)" & vbcrlf
tempSTR =tempSTR & "{" & vbcrlf
tempSTR =tempSTR & "document." & myform & "." & listname2
tempSTR =tempSTR & ".options=new Option(key,"
tempSTR =tempSTR & "key);" & vbcrlf
tempSTR =tempSTR & "}" & vbcrlf
tempSTR =tempSTR & "document." & myForm & "." & listname2
tempSTR =tempSTR & ".length=key.length;" & vbcrlf
tempSTR =tempSTR & "}" & vbcrlf

'再发生 Buildkey1 副程式
function Buildkey1(num)
{
document.myForm.price.selectedIndex=0;
for(ctr=0;ctr<key1.length;ctr++){
document.myForm.price.options=new Option(key1,key1);
}
document.myForm.price.length=key1.length;
}

tempSTR =tempSTR & vbcrlf & "function Buildkey1" & "(num)" & vbcrlf
tempSTR =tempSTR & "{" & vbcrlf
tempSTR =tempSTR & "document." & myForm & "."
tempSTR =tempSTR & listname3 & ".selectedIndex=0;" & vbcrlf
tempSTR =tempSTR & "for(ctr=0;ctr<key1.length;ctr++)" & vbcrlftempSTR =tempSTR & "{" & vbcrlf
tempSTR =tempSTR & "document." & myform & "." & listname3
tempSTR =tempSTR & ".options=new Option(key1,"
tempSTR =tempSTR & "key1);" & vbcrlftempSTR =tempSTR & "}" & vbcrlf
tempSTR =tempSTR & "document." & myForm & "." & listname3
tempSTR =tempSTR & ".length=key1.length;" & vbcrlftempSTR =tempSTR & "}" & vbcrlf
myfun=tempSTR
END sub
%> 写软件都是想的时间比写的时间要长的.如果反过来了就得看看是什么原因了. 另外大家可以回去问问公司里的小MM.(一般企业里,跟你们交付软件接触得最多的是她们)

再现理想 发表于 2015-2-4 01:42:24

多看多学多思。多看一些关于ASP的书籍,一方面可以扩展知识面一方面可以鉴借别人是如何掌握、运用ASP的;多学善于关注别人,向同学老师多多学习,不论知识的大小;多思则是要将学到的知识灵活运用。

海妖 发表于 2015-2-4 01:42:24

你可以通过继承已有的对象最大限度保护你以前的投资。并且C#和C++、Java一样提供了完善的调试/纠错体系。

admin 发表于 2015-2-7 09:55:20

另外因为asp需要使用组件,所以了解一点组件的知识(ADODB也是组件)

老尸 发表于 2015-2-8 05:23:38

在平时的学习过程中要注意现学现用,注重运用,在掌握了一定的基础知识后,我们可以尝试做一些网页,也许在开始的时候我们可能会遇到很多问题,比如说如何很好的构建基本框架。

第二个灵魂 发表于 2015-2-12 06:51:36

ASP主要是用好六个对象,其实最主要的是用好其中两个:response和request,就可以随心所欲地控制网页变换和响应用户动作了。

再见西城 发表于 2015-2-19 19:02:36

以上是语言本身的弱点,在功能方面ASP同样存在问题,第一是功能太弱,一些底层操作只能通过组件来完成,在这点上是远远比不上PHP/JSP,其次就是缺乏完善的纠错/调试功能,这点上ASP/PHP/JSP差不多。

因胸联盟 发表于 2015-3-6 15:18:07

我们必须明确一个大方向,不要只是停留在因为学而去学,我们应有方向应有目标.

爱飞 发表于 2015-3-13 03:08:21

代码的可重用性差:由于是面向结构的编程方式,并且混合html,所以可能页面原型修改一点,整个程序都需要修改,更别提代码重用了。

不帅 发表于 2015-3-20 10:49:56

还有如何才能在最短的时间内学完?我每天可以有效学习2小时,双休日4小时。

透明 发表于 2015-3-21 03:10:33

Request:从字面上讲就是“请求”,因此这个是处理客户端提交的东东的,例如Resuest.Form,Request.QueryString,或者干脆Request("变量名")

灵魂腐蚀 发表于 2015-3-25 09:32:21

从事这个行业,那么你可以学ASP语言,简单快速上手,熟练dreamweav排版,写asp代码,熟练photoshop处理图片,打好基础就行了

活着的死人 发表于 2015-3-26 08:11:21

我就感觉到ASP和一些常用的数据库编程以及软件工程方面的思想是非常重要的。我现在也在尝试自己做网页,这其中就用到了ASP,我想它的作用是可想而知的。

只想知道 发表于 2015-4-1 22:12:09

运用经典的例子。并且自己可以用他来实现一些简单的系统。如果可以对他进行进一步的修改,找出你觉得可以提高性能的地方,加上自己的设计,那就更上一个层次了,也就会真正地感到有所收获。

简单生活 发表于 2015-4-12 03:44:36

接下来就不能纸上谈兵了,最好的方法其实是实践。实践,只能算是让你掌握语言特性用的。而提倡做实际的Project也不是太好,因为你还没有熟练的能力去综合各种技术,这样只能使你自己越来越迷糊。

深爱那片海 发表于 2015-4-16 08:40:50

我认为比较好的方法是找一些比较经典的例子,每个例子比较集中一种编程思想而设计的。

乐观 发表于 2015-4-29 00:35:06

虽然ASP也有很多网络教程。但是这些都不系统。都是半路出家,只是从一个例子告诉你怎么用。不会深入讨论,更不会将没有出现在例子里的方法都一一列举出来。

谁可相欹 发表于 2015-6-11 05:42:35

学习ASP其实应该上升到如何学习程序设计这种境界,其实学习程序设计又是接受一种编程思想。比如ASP如何学习,你也许在以前的学习中碰到过。以下我仔细给你说几点:

山那边是海 发表于 2015-7-1 21:26:20

另外因为asp需要使用组件,所以了解一点组件的知识(ADODB也是组件)

精灵巫婆 发表于 2015-7-5 01:00:38

ASP.Net摆脱了以前ASP使用脚本语言来编程的缺点,理论上可以使用任何编程语言包括C++,VB,JS等等,当然,最合适的编程语言还是MS为.NetFrmaework专门推出的C(读csharp),它可以看作是VC和Java的混合体吧。
页: [1] 2
查看完整版本: ASP网站制作之创立静态下拉式选单(三阶级)