网站投票系统
有两个表。一个存放题目,一个存放选项.
其中voteID=wq_vote.ID
显示所有没有锁定的投票题目:
用DataList:页面代码:
<asp:DataList ID="DataList1" runat="server"
onitemdatabound="DataList1_ItemDataBound"
onitemcommand="DataList1_ItemCommand" BorderStyle="None" GridLines="Vertical" UseAccessibleHeader="True"
>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("vTitle") %>'></asp:Label>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("vType")%>' Visible="false"></asp:Label>
<asp:RadioButtonList ID="rbllist" runat="server">
</asp:RadioButtonList>
<asp:CheckBoxList ID="cbllist" runat="server">
</asp:CheckBoxList>
<br />
<asp:Button ID="btnVote" runat="server" Text="投票" CommandName="btnVote" />
<hr />
<br />
<br />
</ItemTemplate>
</asp:DataList>
当投票时的事件写在:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
{
int id =int.Parse(this.DataList1.DataKeys[e.Item.ItemIndex].ToString());
string iTypes = ((Label)e.Item.FindControl("Label2")).Text.ToString();
RadioButtonList rblList = ((RadioButtonList)e.Item.FindControl("rbllist"));
CheckBoxList cblList = ((CheckBoxList)e.Item.FindControl("cbllist"));
WangQi.Vote.Model.VoteItemModel model = new WangQi.Vote.Model.VoteItemModel();
if (e.CommandName == "btnVote")
{
if (int.Parse(iTypes) == -1)
{
int rblID = int.Parse(rblList.SelectedValue.ToString());
List< WangQi.Vote.Model.VoteItemModel> _list = WangQi.Vote.BLL.VoteItemBll.GetList(0, "ID="+rblID);
model.ID= _list[0].ID;
model.ViCount = _list[0].ViCount + 1;
model.ViContent = _list[0].ViContent;
model.VoteID = _list[0].VoteID;
WangQi.Vote.BLL.VoteItemBll.Update(model);
}
else
{
List<WangQi.Vote.Model.VoteItemModel> _list = new List<WangQi.Vote.Model.VoteItemModel>();
for (int i = 0; i < cblList.Items.Count; i++)
{
if (cblList.Items[i].Selected == true)
{
_list = WangQi.Vote.BLL.VoteItemBll.GetList(0, "ID=" + int.Parse(cblList.Items[i].Value));
model.ID = _list[0].ID;
model.ViCount = _list[0].ViCount + 1;
model.ViContent = _list[0].ViContent;
model.VoteID = _list[0].VoteID;
WangQi.Vote.BLL.VoteItemBll.Update(model);
}
}
}
WangQi.Utils.WQJavascript.JsAlert("投票成功!");
}
}