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 判断数据库是否存在,表是否存在
if DB_ID('testdb') is not null -- 如果这个数据库已经存在了 drop database testdb; create database testdb; if OBJE ...
- CentOS下重新安装yum
1,下载最新的yum-3.2.28.tar.gz并解压 #wget http://yum.baseurl.org/download/3.2/yum-3.2.28.tar.gz#tar xvf yum- ...
- android 用 XML 自定义边框(只上下边框有色)
直接上代码: <?xml version="1.0" encoding="UTF-8"?> <layer-list xmlns:android ...
- 一个基于Qt的截屏程序
最近有一个arm板上的程序需要重写用户手册,在网上找了许久,没找到合适的截屏工具.于是只好自己动手做一个了. 因为arm板上有已经有了Qt环境,于是想到用 Qt的QPixmap::grabWindow ...
- [Leetcode][Python]21: Merge Two Sorted Lists
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 21: Merge Two Sorted Listshttps://oj.le ...
- 特卖电商俏物悄语或面临破产 ihush域名夭折?:域名新闻:域名门户:eName.CN
特卖电商俏物悄语或面临破产 ihush域名夭折?:域名新闻:域名门户:eName.CN 特卖电商俏物悄语或面临破产 ihush域名夭折?
- CouldnotcreateServerSocketonaddress0.0.0.0/0.0.0.0:9083
错误记录 安装的时候遇到了如下错误 Exception in thread "main" org.apache.thrift.transport.TTransportExcepti ...
- mac文件权限
如何设置文件/或文件夹权限为777 进入终端,切换到指定目录,输入以下命令,后面添加你的文件名/目录名$sudo chmod -R 777 (文件名/目录名) 或 $chmod 777 ./test. ...
- Ubuntu小私房(3)--Uubutnu启动美化大变身
Grub是什么? GNU GRUB 和GRUB是GRand Unified Bootloader的缩写,它是一个多重操作系统启动管理器.用来引导不同系统,如windows,linux.GRUB是多启动 ...
- HTML:scrollLeft,scrollWidth,clientWidth,offsetWidth到底指的哪到哪的距离之完全详解
scrollHeight: 获取对象的滚动高度. scrollLeft:设置或获取位于对象左边界和窗口中目前可见内容的最左端之间的距离 scrollTop:设置或获取位于对象最顶端和窗口中可见内容的最 ...