创建数据库:

CREATE table DiaoYanTiMu
(
Ids int primary key ,--题目代号
Title varchar() not null ,--要调查的题目
SelectionType int,--单选多选代号,-单选,-多选
IsOver bit,--是否结束,true-结束,flase-未结束
)
GO CREATE table DiaoYanXuanXiang
(
Ids varchar()primary key,
Options varchar(),--调研每个题目的选项内容
Numebers int,--选择此调研选项的人数
TiMuDaiHao int references DiaoYanTiMu(Ids),--所属调研题目的代号
)
INSERT into DiaoYanTiMu VALUES('','晚上在家干啥?','','')
INSERT INTO DiaoYanTiMu VALUES('','自己那个地方有欠缺','','')
INSERT INTO diaoyanxuanxiang VALUES('','玩游戏','','')
INSERT INTO diaoyanxuanxiang VALUES('','睡觉','','')
INSERT INTO diaoyanxuanxiang VALUES('','吃饭打豆豆','','')
INSERT INTO diaoyanxuanxiang VALUES('','做练习','','')
INSERT INTO diaoyanxuanxiang VALUES('','知识点不会','','')
INSERT INTO diaoyanxuanxiang VALUES('','听不懂','','')
INSERT INTO diaoyanxuanxiang VALUES('','比较懒欠练习','','')
INSERT INTO diaoyanxuanxiang VALUES('','解决能力弱','','')
INSERT INTO diaoyanxuanxiang VALUES('','缺乏资源','','')
SELECT * from DiaoYanTiMu
SELECT * FROM diaoyanxuanxiang

aspx代码:

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Import Namespace="System.Linq" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<style type="text/css">
* {
margin:0px;
padding:0px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server"></asp:Label>
<br />
<%-- 显示题目内容 --%>
<div id="vote" style="width:500px;height:300px">
<asp:CheckBoxList ID="CheckBoxList1" runat="server">
</asp:CheckBoxList>
<br />
<asp:Button ID="Button1" runat="server" Text="提交" OnClick="Button1_Click" />
&nbsp;
<input type="button" value="查看结果" onclick="xianshi()" /> </div>
<%-- 显示结果 --%>
<div id ="result" style="display:none;">
<ul style ="list-style:none">
<%
contestDataContext _context = new contestDataContext();
var query = _context.DiaoYanXuanXiang.Where(p=>p.TiMuDaiHao==).ToList();
int sum = query.Sum(p => p.Numebers).Value;//总票数
//分别去取值,增加宽度
foreach(DiaoYanXuanXiang data in query)
{
int ps = data.Numebers.Value;//投的票数,获取出来
double bf = Math.Round(((ps * 1.0) / sum) * , );//math.round(数值,取小数点后几位),取余数;数值*1.0后操作可以变小数;整数除以整数是整数
double width = bf * ;
%>
<li style ="width:600px;height:20px; margin-top:10px">
<div style="width:150px;height:20px; float:left"><%=data.Options%></div>
<div style ="width:200px;height:20px; background-color:#f6f1f1; float:left;">
<div style="width:<%=width%>px;height:20px; background-color:#00ff21"></div>
</div>
<div style="width:20px;height:20px; float:left;"><%=data.Numebers%></div>
<div style="width:80px;height:20px; float:left;">(<%=bf%>%)</div>
</li>
<%
}
%> </ul>
<input type="button" value="返回" onclick="fanhui()" />
</div>
</div>
</form>
<script type="text/javascript">
function fanhui()
{
document.getElementById("vote").style.display = "block";
document.getElementById("result").style.display = "none";
}
function xianshi() {
document.getElementById("result").style.display = "block";
document.getElementById("vote").style.display = "none";
}
</script>
</body>
</html>

aspx.cs代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls; public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//查询题目
contestDataContext _contest = new contestDataContext();
var query = _contest.DiaoYanTiMu.Where(p=>p.Ids ==);
Label1.Text = query.First().Title; //显示题目名称
CheckBoxList1.DataSource = _contest.DiaoYanXuanXiang.Where(p=>p.TiMuDaiHao==query.First().Ids);
CheckBoxList1.DataTextField = "Options";
CheckBoxList1.DataValueField = "Ids";
CheckBoxList1.DataBind();
}
} protected void Button1_Click(object sender, EventArgs e)
{
contestDataContext _contest = new contestDataContext();
//取投票的项,将票项更改
foreach(ListItem list in CheckBoxList1.Items)
{
if(list.Selected)
{
var query = _contest.DiaoYanXuanXiang.Where(p=>p.Ids == list.Value);//每一项只有一个value
query.First().Numebers += ;
_contest.SubmitChanges();
}
} }
}

Webform之(简单投票)练习的更多相关文章

  1. MVC与WebForm的简单的比较

    MVC与WebForm的简单的比较 ASP 强制程序员将业务逻辑和展示页放到一个文件中 WebForm 允许程序员将业务逻辑与页面展示分开到不同的文件中,并且提供强大的开发平台来写  业务逻辑代码  ...

  2. Webform(简单控件、复合控件)

    一.简单控件: 1.label控件 <asp:Label ID="Label1" runat="server" Text="账 号:" ...

  3. 使用Seam Framework + JBoss 5.0 开发第一个Web应用 - 简单投票程序

    Seam这个单词的本意是缝合.连接,因而,Seam的作用即是把Java EE 规范里的JSF 和 EJB技术完美融合在一起,免去了很多胶合代码,并增强了JSF 和 EJB的很多功能.Seam的设计目标 ...

  4. WebForm 【简单控件】【表单元素】

    一.HTML 表单元素复习 (1)文本类 文本框:<input type="text" name="" id="" value=&qu ...

  5. vue,一路走来(15)--简单投票系统

    今天记录一下简单的投票系统,主要实现选中至少五张作品,并提交投票. 思路:选中作品,将作品id存入到数组里. 取消投票,则从数组中移除该作品id. 如图效果: <li v-for="( ...

  6. 使用TaskManager爬取2万条代理IP实现自动投票功能

    话说某天心血来潮想到一个问题,朋友圈里面经常有人发投票链接,让帮忙给XX投票,以前呢会很自觉打开链接帮忙投一票.可是这种事做多了就会考虑能不能使用工具来进行投票呢,身为一名程序猿决定研究解决这个问题. ...

  7. 一、ASP.NET MVC 路由(一)--- ASP.NET WebForm路由模拟

    ASP.NET WebForm 应用,用户请求的是物理文件,其中包括静态页面和动态页面,在Url中的显示都是服务器中一个物理文件的相对路径.但是ASP.NET MVC就不同了,用户请求的是Contro ...

  8. ASP.NET WebForm路由模拟

    一.ASP.NET MVC 路由(一)--- ASP.NET WebForm路由模拟 2014-11-08 11:49 by 郝喜路, 232 阅读, 0 评论, 收藏, 编辑 ASP.NET Web ...

  9. Bagging与随机森林算法原理小结

    在集成学习原理小结中,我们讲到了集成学习有两个流派,一个是boosting派系,它的特点是各个弱学习器之间有依赖关系.另一种是bagging流派,它的特点是各个弱学习器之间没有依赖关系,可以并行拟合. ...

随机推荐

  1. svn 同步到web目录

    windows  hook 下 @echo offSET REPOS=%1SET REV=%2SET DIR=%REPOS%/hooksSET PATH=%PATH%;SET WORKING=D:/w ...

  2. IIS应用程序池监控

    最近发现公司运行的web网站应用程序池会突然停止,做的负载均衡(路由负载)又无法监测到IIS应用程序池的情况,就想着通过某一种监控方式监测IIS应用程序池的情况,如果处关闭状态则立刻重新启动.所说的I ...

  3. hdu 1210_(逻辑训练)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1210 #include<stdio.h> int main() { int n,t,sum ...

  4. 随心所欲~我也做个集合遍历器吧(自己的foreach,委托的威力)

    感觉微软在面向对象三大原则中,封装性运用的最为突出,它会将一些复杂的算法,结构,功能代码进行封装,让程序员在使用时十分得心应手,如关键字里的foreach和labmda表达式里的Foreach等等,今 ...

  5. How many ways(记忆化搜索)

    How many ways Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) To ...

  6. UVA 12075 - Counting Triangles(容斥原理计数)

    题目链接:12075 - Counting Triangles 题意:求n * m矩形内,最多能组成几个三角形 这题和UVA 1393类似,把总情况扣去三点共线情况,那么问题转化为求三点共线的情况,对 ...

  7. hdu3038 How Many Answers Are Wrong【基础种类并查集】

    转载请注明出处,谢谢:http://www.cnblogs.com/KirisameMarisa/p/4298091.html   ---by 墨染之樱花 题目链接:http://acm.hdu.ed ...

  8. 记hive select distinct 多列 误区一则

    当select distinct a,b,c时,只会对a.b.c都起作用,无法达到只顾虑多余的a列: 根据hive官方网站说明:当有表 a b 10 1 10  2 10 3 此时select a,b ...

  9. Hibernate session.saveOrUpdate()方法

    saveOrUpdate()方法同时包含了save()与update()方法的功能, 如果传入的参数是临时对象,就调用save()方法: 如果传入的参数是游离对象,就调用update()方法: 如果传 ...

  10. 使用VisualStudio发布ASP.NET网站

    1.右击网站点击“发布网站” 2.选择或导入发布配置文件.→新建配置文件. 3.输入名称test.→点击确定. 4.发布方法选择文件系统. 5.选择目标位置.→点击下一步 6.文件发布选项选择三个选项 ...