哈尔滨有钱人排名:网页制作问题】】】】进来!

来源:百度文库 编辑:查人人中国名人网 时间:2024/04/27 23:29:53
怎样实现让来访者在线投票功能?
而且要能看在线投票结果的

可以做一个代码

代码1:
<%@ Page Language="VB" ContentType="text/html" %>
<%@ Import Namespace="system.data" %>
<%@ Import Namespace="system.data.sqlclient" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
<style type="text/css">
<!--
td {
font-size: 9pt;
}
-->
</style>
</head>
<body>
<form runat="server">
<table width="200" border="0" cellpadding="0" cellspacing="0" bgcolor="#EEEEEE">
<tr>
<td height="25" colspan="2"><font face="Geneva, Arial, Helvetica, sans-serif"><strong>VoteOnline</strong></font></td>
</tr>
<tr>
<td height="25" colspan="2"> 请选择你最喜欢的水果?</td>
</tr>
<tr>
<td width="29" height="25"> </td>
<td width="171" height="25"> <asp:radiobuttonlist ID="rblVoteitem" runat="server">
<asp:listitem selected>芒果</asp:listitem>
<asp:listitem>榴莲</asp:listitem>
<asp:listitem>桃子</asp:listitem>
<asp:listitem>西瓜</asp:listitem>
</asp:radiobuttonlist></td>
</tr>
<tr>
<td height="25"> </td>
<td height="25"><asp:button ID="butvote" runat="server" Text="投票" onclick="butvote_click" />
<asp:button ID="butview" runat="server" Text="查看" /> </td>
</tr>
</table>
</form>
</body>
</html>
<script runat="server">
Sub butvote_click(Src As Object, E As EventArgs)
if session("voted")<>true then

dim conn as sqlconnection
dim comm as sqlcommand
dim str as string

conn = new sqlconnection("server=192.168.0.67;uid=sa;pwd=sa;database=fjh")
conn.open()

str = "update vote set 票数=票数+1 where 水果='" & rblVoteitem.selecteditem.text & "'"

comm = new sqlcommand(str,conn )

try
comm.executenonquery()
conn.close()

session("voted")="true"

Response.Write("<script language=javascript>alert('感谢你的投票')</s"+"cript>")
Catch
Response.Write("<script language=javascript>alert('出现异常错误')</s"+"cript>")
conn.close()
end try

else
Response.Write("<script language=javascript>alert('你已经投过票了,请不要重复投票')</s"+"cript>")
end if

End Sub

Sub view_click(src As Object, e As EventArgs)
response.Redirect("viewvote.aspx")
End Sub

</script>
参考地址:http://www.yblog.net/blog/user1/655/archives/2005/3085.html

代码2:
<form name="vote" method="post" action="http://www.canonfans.com/poll/poll.php" target=_blank>
EOS相机小调查<br>
<input type=hidden name=pid value=9>
<input type=radio name=optionid value=26>我还没有EOS相机,准备购买EOS单反相机(胶片机)。<br>
<input type=radio name=optionid value=27>我还没有EOS相机,准备购买EOS数码单反相机。<br>
<input type=radio name=optionid value=28>我已经拥有EOS胶片相机,准备购买EOS数码单反相机。<br>
<input type=radio name=optionid value=29>我已经拥有EOS数码单反相机,准备购买EOS胶片相机。<br>
<input type=radio name=optionid value=30>我已经拥有其他品牌或型号的数码相机,准备购买EOS胶片相机。<br>
<input type=radio name=optionid value=31>我已经拥有其他品牌或型号的数码相机,准备购买EOS数码单反相机。<br>
<input type=radio name=optionid value=32>我已经拥有EOS胶片相机,准备升级或再购买一套EOS胶片相机。<br>
<input type=radio name=optionid value=33>我已经拥有EOS数码单反相机,准备升级或再购买一套EOS数码单反相机。<br>
<input type=hidden name=omax value=8>
<input type=submit value='投票'>
<input type=button value='结果' onclick="javascript:window.open('http://www.canonfans.com/poll/result.php?pid=9');">
</form>