Webform之(简单投票)练习


创建数据库:
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" />
<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之(简单投票)练习的更多相关文章
- MVC与WebForm的简单的比较
MVC与WebForm的简单的比较 ASP 强制程序员将业务逻辑和展示页放到一个文件中 WebForm 允许程序员将业务逻辑与页面展示分开到不同的文件中,并且提供强大的开发平台来写 业务逻辑代码 ...
- Webform(简单控件、复合控件)
一.简单控件: 1.label控件 <asp:Label ID="Label1" runat="server" Text="账 号:" ...
- 使用Seam Framework + JBoss 5.0 开发第一个Web应用 - 简单投票程序
Seam这个单词的本意是缝合.连接,因而,Seam的作用即是把Java EE 规范里的JSF 和 EJB技术完美融合在一起,免去了很多胶合代码,并增强了JSF 和 EJB的很多功能.Seam的设计目标 ...
- WebForm 【简单控件】【表单元素】
一.HTML 表单元素复习 (1)文本类 文本框:<input type="text" name="" id="" value=&qu ...
- vue,一路走来(15)--简单投票系统
今天记录一下简单的投票系统,主要实现选中至少五张作品,并提交投票. 思路:选中作品,将作品id存入到数组里. 取消投票,则从数组中移除该作品id. 如图效果: <li v-for="( ...
- 使用TaskManager爬取2万条代理IP实现自动投票功能
话说某天心血来潮想到一个问题,朋友圈里面经常有人发投票链接,让帮忙给XX投票,以前呢会很自觉打开链接帮忙投一票.可是这种事做多了就会考虑能不能使用工具来进行投票呢,身为一名程序猿决定研究解决这个问题. ...
- 一、ASP.NET MVC 路由(一)--- ASP.NET WebForm路由模拟
ASP.NET WebForm 应用,用户请求的是物理文件,其中包括静态页面和动态页面,在Url中的显示都是服务器中一个物理文件的相对路径.但是ASP.NET MVC就不同了,用户请求的是Contro ...
- ASP.NET WebForm路由模拟
一.ASP.NET MVC 路由(一)--- ASP.NET WebForm路由模拟 2014-11-08 11:49 by 郝喜路, 232 阅读, 0 评论, 收藏, 编辑 ASP.NET Web ...
- Bagging与随机森林算法原理小结
在集成学习原理小结中,我们讲到了集成学习有两个流派,一个是boosting派系,它的特点是各个弱学习器之间有依赖关系.另一种是bagging流派,它的特点是各个弱学习器之间没有依赖关系,可以并行拟合. ...
随机推荐
- SQL Server 全文索引
create table Document(ID int not null,Name nvarchar(255) not null,Body nvarchar(max) not null);go cr ...
- J2SE知识点摘记(二十二)
Map 1.4.1 概述 数学中的映射关系在Java中就是通过Map来实现的.它表示,里面存储的元素是一个对(pair),我们通过一个对象,可以在这个映射关系中找到另外一个和这个对象相关 ...
- 关于android 1.6全部的权限介绍
原文:关于android 1.6全部的权限介绍 我们在 AndroidManifest.xml里需要对一些软件需要的操作做一些权限的声明,比如我们的软件有发送短信的功能,那么就需要在 AndroidM ...
- Silverlight第三方控件专题
原文http://www.cnblogs.com/nasa/archive/2008/12/01/1344927.html 这里我收集整理了目前网上silverlight第三方控件的专题,若果有所遗漏 ...
- git 配置文件
设置记住密码(默认15分钟): git config --global credential.helper cache 如果想自己设置时间,可以这样做: git config credential.h ...
- ubuntu中如何关闭防火墙?
只需要输入 root@stgman-desktop:~# sudo ufw disable 防火墙在系统启动时自动禁用
- 面向对象程序设计-C++_课时13初始化列表
构造函数设置成员初值方法有两种:一种是在函数体内赋值,另一种是采用初始化列表的形式. 初始化列表BETTER 函数体内赋值 类名::类名(形参1,形参2,...形参n) { 数据成员1=形参1; 数据 ...
- MD5和sha1加密算法
在很多电子商务和社区应用中,我们都要存放很多的客户的资料,其中包括了很多的隐私信息和客户不愿被别人看到的信息,当然好有客户执行各种操作的密码,此时就需要对客户的信息进行加密再存储,目前有两种比较好的加 ...
- fork进程函数总结
学习链接: http://blog.csdn.net/jason314/article/details/5640969 http://coolshell.cn/articles/7965.html 搜 ...
- Oracle包的概念
转自:http://www.cnblogs.com/lovemoon714/archive/2012/02/29/2373695.html 1.为什么要使用包? 答: 在一个大型项目中,可 ...