日期:2014-05-18 浏览次数:20586 次
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="toupiao.ascx.cs" Inherits="XmlVote.toupiao" %>
<fieldset>
<legend accesskey="F" style="FONT-WEIGHT:bold;COLOR:#000000;font-size:12px" align=center>
<%=VoteTitle%></legend>
<ul style="list-style-type:none;margin-left:50px">
<%for(int i=0;i<xnl.Count;i++)
{
System.Xml.XmlNode xn = xnl.Item(i);%>
<li>
<input type=checkbox name="vote" value="<%=xn.SelectSingleNode("VoteID").InnerText%>" /><%=xn.SelectSingleNode("Title").InnerText%>
<%}%>
</li>
</ul>
<div align=center><asp:Button id="Vote" runat="server" Text="投票" OnClick="Vote_Click"></asp:Button> <input
type=button value="查看结果"
onclick="javascript:var url='vote/ShowVote.aspx?i=0&voteid=<%=Request.QueryString["VoteID"]%>';window.open(url,'_blank','left=10,top=20,width=675,height=360');return false;"
style="height: 26px" /></div>
</fieldset>
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml;
namespace XmlVote
{
public partial class toupiao : System.Web.UI.UserControl
{
protected XmlNodeList xnl;
protected string VoteTitle = "";
protected System.Web.UI.WebControls.Button Button1;
private XmlDocument myDoc = new XmlDocument();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
BindXML("1");
}
private void BindXML(string VoteID)
{
myDoc.Load(Server.MapPath("vote/DB_hyy.xml"));
XmlNode xn = myDoc.SelectSingleNode("//VoteInfo[ID='" + VoteID + "']");
VoteTitle = xn.SelectSingleNode("VoteTitle").InnerText;
xnl = xn.SelectNodes("Item");
}
protected void Vote_Click(object sender, EventArgs e)
{
string VoteID = "1";
//通过Cookie记录投票
if (Request.Cookies["IsVote"] != null)
{
Response.Write("<script>alert('对不起,你已投过票!');document.location=document.location;</script>");
}
else
{
if (Request.Form["Vote"] != null && Request.Form["Vote"] != "")
{
string[] votes = Request.Form["Vote"].Split(',');
myDoc.Load(Server.MapPath("vote/DB_hyy.xml"));
XmlNode xn = myDoc.SelectSingleNode("//VoteInfo[ID='" + VoteID + "']");
for (int i = 0; i < votes.Length - 1;