```
=rs("PollQuestion")
``` ```For I=1 To 5 choice = rs("Choice" & I) If choice <> "" Then
1 <tr> <!-- <td width=50 colspan=1 bgcolor=#4f4f4f> </td> \-->
2 <td align="left" bgcolor="#FFFFFF" class="bold" colspan="2">
=choice
</td><td align="left" bgcolor="#FFFFFF"><input name="choice" type="radio" value="
=I
End If Next
1
2 </table></form></td></tr>
If rs("GetName") = "1" Then
1 <tr><td align="right" bgcolor="#FFFFFF" class="bold" colspan="1">
2 Your Name:</td>
3 <td align="right" bgcolor="#FFFFFF" colspan="2">
4 <input name="Name" type="text"/>
5 </td></tr>
End If
1 <tr>
2 <td align="center" bgcolor="#000000" colspan="3">
3 <input class="inline" type="submit" value="Submit Vote"/>
4 </td></tr>
5 </table>
6
Else Response.Write "Invalid Poll Id Request!" End If
1 </td></tr></table>
2
3
4
5 </body>
6 </html>
5、文件global.asa
1 <script language="VBScript" runat="SERVER">
2
3 Sub Application_OnStart
4 Application("ASP_Poll") = "ASP_Poll"
5 cnString = "DRIVER={Microsoft Access Driver (*.mdb)}; "
6 cnString = cnString & "DBQ=" & Server.MapPath("Events.mdb")
7 Application("ASPPollDSN") = cnString
8 End Sub
9 </script>
6、文件pool.inc
1
2 DBPath = Server.MapPath("/poll/Events.mdb")
3 ID = 28
4 If Request.Cookies("PollID") = CStr(ID) Then
5 ShowDisplay
6 Else
7 ShowVote
8 End If
9
10 Function ConvertToPercent(total, sz)
11 If sz = 0 Then
12 ConvertToPercent = "0%"
13 Else
14 ConvertToPercent = FormatPercent(sz/total, 2)
15 End If
16 End Function
17
18 Sub ShowVote
19
1 <div align="right">
2 <table border="1" cellpadding="0" cellspacing="0" width="125"><tr><td>
3 <form action="/poll/collect.asp" method="post">
4 <input name="id" type="hidden" value="```
5 =id
6 ```"/>
7 <input ```"="" name="return_page" path_info")="" type="hidden" value="```
8 =Request.ServerVariables("/>
Set conn = Server.CreateObject("ADODB.Connection") dsnpath = "DRIVER={MICROSOFT ACCESS DRIVER (*.mdb)}; " dsnpath = dsnpath & "DBQ=" & DBPath conn.open dsnpath sql = "select * from Poll where ID = " & ID Set rs = conn.Execute(sql) If rs.EOF = False Then
1
2 <table bgcolor="#4f4f4f" border="0" cellpadding="2" cellspacing="0" width="125">
3 <tr>
4 <td align="center" bgcolor="#2f2f4f" colspan="3">
=rs("PollQuestion")
For I=1 To 5 choice = rs("Choice" & I) If choice <> "" Then
1 <tr>
2 <td bgcolor="#000000" colspan="2" valign="top" width="80%">
=choice
</td><td bgcolor="#000000" colspan="1" valign="top" width="20%"> <input name="choice" type="radio" value="
=I
End If Next
1
2 <tr>
3 <td align="right" bgcolor="#2f2f4f" colspan="3">
4 <input class="nav" type="submit" value="Submit"/>
5 </td></tr>
6 </table>
End If
1
2 </form></td></tr></table>
3
4
End Sub
Sub ShowDisplay
Set conn = Server.CreateObject("ADODB.Connection") sql = "select * from Poll where ID = " & Cint(ID) dsnpath = "DRIVER={MICROSOFT ACCESS DRIVER (.mdb)}; " dsnpath = dsnpath & "DBQ=" & DBPath conn.open dsnpath Set rs = Conn.Execute(sql) If rs.EOF = False Then Dim Choices(6) Dim Responses(6) For I=1 To 5 choice = rs("Choice" & I) Choices(I) = choice If choice <> "" Then Set conn2 = Server.CreateObject("ADODB.Connection") sql = "select COUNT(PollAnswer) from PollResults where PollID = " & Cint(id) & " AND PollAnswer=" & I dsnpath = "DRIVER={MICROSOFT ACCESS DRIVER ( .mdb)}; " dsnpath = dsnpath & "DBQ=" & DBPath conn2.open dsnpath Set rs2 = Conn.Execute(sql) If rs2.EOF = False Then Responses(I) = rs2(0) End If rs2.Close conn2.Close End If Next
1 <div align="right">
2 <table border="1" cellpadding="2" cellspacing="0"><tr><td>
3 <table border="0" cellspacing="0" width="125"><tr>
4 <td align="center" bgcolor="#2f2f4f" class="orgbold" colspan="2">ASP Poll
5 </td></tr>
6 <tr><td align="center" bgcolor="#ccccff" class="black" colspan="2">
7 Q:```
8 =rs("PollQuestion")
1
2 Total = 0
3 For I=1 To 5
4 responseCount = Responses(I)
5 If responseCount &lt;&gt; "" Then
6 Total = Total + Cint(responseCount)
7 End If
8 Next
9 For I=1 To 5
10 choice = Choices(I)
11 responseCount = Responses(I)
12 If choice &lt;&gt; "" Then
13 Response.Write "<tr><td align="left" colspan="1"><font color="#f0f0f0" face="verdana" size="-1">"
14 Response.Write choice
15 Response.Write "</font></td>"
16 Response.Write "<td>" &amp; ConvertToPercent(total, responseCount) &amp; "</td>"
17 Response.Write "</tr>"
18 End If
19 Next
20 Response.Write "</table></td></tr></table></div>"
21 End If
22 End Sub
``` Published At2005-12-18 03:39 UTC