
前台
1
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="VoteIndex.aspx.cs" Inherits="user_VoteIndex" %>
2
3
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4
<html xmlns="http://www.w3.org/1999/xhtml">
5
6
<script language="javascript" type="text/javascript">
7
var checkSubmitFlg = false;
8
function checkSubmit()
{
9
if (checkSubmitFlg == true)
{
10
return false;
11
}
12
checkSubmitFlg = true;
13
return true;
14
}
15
document.ondblclick = function docondblclick()
{
16
window.event.returnValue = false;
17
}
18
document.onclick = function doconclick()
{
19
if (checkSubmitFlg)
{
20
window.event.returnValue = false;
21
}
22
}
23
</script>
24
25
<head runat="server">
26
<title>用户投票页面</title>
27
<link href="../css/main.css" type="text/css" rel="stylesheet" />
28
</head>
29
<body style="background-image: url(../images/bg-2.jpg)">
30
<form id="form1" runat="server">
31
<div>
32
<table border="1" cellpadding="0" cellspacing="0" class="tableframe" width="100%">
33
<tr>
34
<td class="titlebar" colspan="5" style="width: 100%; height: 30px; background-color: #cce4f7"
35
valign="middle">
36
<img alt="" src="../images/cg.gif" />Users vote page</td>
37
</tr>
38
<tr>
39
<td align="left" colspan="1" style="width: 85%">
40
41
<asp:DataList ID="dlVote" runat="server" Width="50%" OnItemDataBound="dlVote_ItemDataBound"
42
OnItemCommand="dlVote_ItemCommand">
43
<ItemTemplate>
44
<table cellpadding="0" cellspacing="0" width="100%">
45
<tr>
46
<td style="height: 30px; width: 100%">
47
<asp:Label ID="lbName" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.title") %>'></asp:Label>
48
<asp:Label ID="lbId" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.vtid") %>'
49
Visible="false"></asp:Label>
50
</td>
51
</tr>
52
<tr>
53
<td style="width: 100%;">
54
<asp:RadioButtonList ID="rbtVote" runat="server" Visible='<%# DataBinder.Eval(Container, "DataItem.allow") %>'>
55
</asp:RadioButtonList>
56
<asp:CheckBoxList ID="cblVote" runat="server" Visible='<%# DataBinder.Eval(Container, "DataItem.allow") %>'>
57
</asp:CheckBoxList>
58
</td>
59
</tr>
60
<tr>
61
<td style="height: 30px; width: 100%;" align="center">
62
<asp:Button ID="btnAdd" runat="server" Text="投票" CssClass="submit" CommandName="Add" />
63
<asp:Button ID="btnShow" runat="server" Text="显示" CssClass="submit" CommandName="Show" />
64
</td>
65
</tr>
66
</table>
67
</ItemTemplate>
68
</asp:DataList></td>
69
</tr>
70
<tr>
71
<td align="center" colspan="5" style="height: 30px; background-color: #e6f2fb">
72
73
</td>
74
</tr>
75
</table>
76
</div>
77
</form>
78
</body>
79
</html>
80
81

后台
1
using System;
2
using System.Data;
3
using System.Configuration;
4
using System.Collections;
5
using System.Web;
6
using System.Web.Security;
7
using System.Web.UI;
8
using System.Web.UI.WebControls;
9
using System.Web.UI.WebControls.WebParts;
10
using System.Web.UI.HtmlControls;
11
12
public partial class user_VoteIndex : System.Web.UI.Page
13

{
14
Recordset rd = new Recordset();
15
protected void Page_Load(object sender, EventArgs e)
16
{
17
if (!IsPostBack)
18
{
19
dlVoteSetValue();
20
}
21
}
22
23
24
25
对DataList 赋值#region 对DataList 赋值
26
/**//// <summary>
27
/// 对DataList 赋值
28
/// </summary>
29
public void dlVoteSetValue()
30
{
31
string sselect = "select * from voteTitle order by adddate desc";
32
33
this.dlVote.DataSource = rd.ExecuteDataTable(sselect, "votetitle");
34
this.dlVote.DataKeyField = "vtid";
35
this.dlVote.DataBind();
36
}
37
#endregion
38
39
获取选项类型#region 获取选项类型
40
/**//// <summary>
41
/// 获取选项类型
42
/// </summary>
43
/// <param name="sTitle"></param>
44
/// <returns></returns>
45
public string getType(int ivtid)
46
{
47
string sselect = "select * from voteTitle where vtid=" + "'" + ivtid + "'" + "";
48
//"select * from voteTitle where vtallow="+"'"+"true"+"'"+"";
49
DataTable ds = rd.ExecuteDataTable(sselect, "votetitle");
50
string sType = ds.Rows[0]["type"].ToString();
51
return sType;
52
}
53
#endregion
54
55
获取 小类表 ID#region 获取 小类表 ID
56
/**//// <summary>
57
/// 获取 小类表 ID
58
/// </summary>
59
/// <param name="sstitle"></param>
60
/// <returns></returns>
61
public int getivcid(string scontent)
62
{
63
string sselect = "select * from voteTitle where vccontent=" + "'" + scontent + "'" + "";
64
DataTable ds = rd.ExecuteDataTable(sselect, "votecontent");
65
int iVtid = Convert.ToInt32(ds.Rows[0]["vcid"]);
66
return iVtid;
67
}
68
#endregion
69
70
71
DataList 绑定事件#region DataList 绑定事件
72
/**//// <summary>
73
/// DataList 绑定事件
74
/// </summary>
75
/// <param name="sender"></param>
76
/// <param name="e"></param>
77
protected void dlVote_ItemDataBound(object sender, DataListItemEventArgs e)
78
{
79
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.EditItem)
80
{
81
RadioButtonList rbt = (RadioButtonList)e.Item.FindControl("rbtVote");
82
Label lb = (Label)e.Item.FindControl("lbId");
83
CheckBoxList cbl=(CheckBoxList)e.Item.FindControl("cblVote");
84
//判断 是否显示 visbis
85
86
int iVtid = Int32.Parse(lb.Text);
87
88
string sSql = "select * from VoteContent where vcallow=1 and vtid=" + iVtid;
89
string sType = getType(iVtid);
90
ArrayList al = rd.ExecuteArrayList(sSql);
91
92
if (al.Count > 0)
93
{
94
for (int i = 0; i < al.Count; i++)
95
{
96
if ("Radio".Equals(getType(iVtid)))
97
{
98
rbt.Items.Add(new ListItem(((Hashtable)al[i])["vccontent"].ToString().Trim(), ((Hashtable)al[i])["vcid"].ToString().Trim()));
99
}
100
else
101
{
102
cbl.Items.Add(new ListItem(((Hashtable)al[i])["vccontent"].ToString().Trim(), ((Hashtable)al[i])["vcid"].ToString().Trim()));
103
}
104
}
105
}
106
}
107
}
108
#endregion
109
ItemCommand 事件#region ItemCommand 事件
110
/**//// <summary>
111
/// ItemCommand 事件
112
/// </summary>
113
/// <param name="source"></param>
114
/// <param name="e"></param>
115
protected void dlVote_ItemCommand(object source, DataListCommandEventArgs e)
116
{
117
if (e.CommandName == "Add")
118
{
119
RadioButtonList rbt = (RadioButtonList)e.Item.FindControl("rbtVote");
120
CheckBoxList cbl = (CheckBoxList)e.Item.FindControl("cblVote");
121
Label lb = (Label)e.Item.FindControl("lbId");
122
int iVtid = Int32.Parse(lb.Text);
123
string sType = getType(iVtid);
124
string IP = Request.ServerVariables["Remote_Addr"];
125
126
if ("Radio".Equals(sType))
127
{
128
for (int i = 0; i < rbt.Items.Count; i++)
129
{
130
if (rbt.Items[i].Selected)
131
{
132
int ivcid = int.Parse(rbt.Text);
133
string sUpdate = "update voteContent set quantity=quantity+1 where vcid='" + ivcid + "'";
134
string sInsert = "insert into VoteUser(vuip,vcid) values('" + IP + "','" + ivcid + "')";
135
136
rd.ExecuteSql(sUpdate);
137
rd.ExecuteSql(sInsert);
138
139
Response.Write("<script>alert('谢谢投票');</script>");
140
141
Response.Redirect("VoteIndex.aspx");
142
143
}
144
}
145
}
146
else
147
{
148
for (int i = 0; i < cbl.Items.Count; i++)
149
{
150
if (cbl.Items[i].Selected)
151
{
152
153
int ivcid = int.Parse(cbl.Text);
154
string sUpdate = "update voteContent set quantity=quantity+1 where vcid='" + ivcid + "'";
155
string sInsert = "insert into VoteUser(vuip,vcid) values('" + IP + "','" + ivcid + "')";
156
157
rd.ExecuteSql(sUpdate);
158
rd.ExecuteSql(sInsert);
159
160
Response.Write("<script>alert('谢谢投票');</script>");
161
Response.Redirect("VoteIndex.aspx");
162
}
163
}
164
}
165
}
166
else
167
{
168
Label lb = (Label)e.Item.FindControl("lbId");
169
int iVtid = Int32.Parse(lb.Text);
170
Response.Redirect("Displayed.aspx?vtid=" + iVtid + "");
171
}
172
}
173
#endregion
174
}
175
176
posted @
2008-10-21 10:09
UouHt
阅读(
274)
评论()
收藏
举报