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流派,它的特点是各个弱学习器之间没有依赖关系,可以并行拟合. ...
随机推荐
- 限制Inactive物料录入BOM
应用 Oracle Bill Of Materiel 层 Level Function 函数名 Funcgtion Name CUX_BOMFDBOM 表单名 Form Name CUXBOMFD ...
- wifi相关协议
IEEE 802.11Wi-Fi 协议摘要 协议 频率 信号 最大,数据率 传统802.11 2.4GHz FHSS或DSSS 2Mbps 802.11a 5GHz OFDM 54Mbps 802.1 ...
- git创建标签
创建标签 在Git中打标签非常简单,首先,切换到需要打标签的分支上: $ git branch * dev master $ git checkout master Switched to branc ...
- JAVA代码静态检测之PMD
今天再次想启动Java代码静态检测工具的利用问题,主要再次尝试用了PMD,发现不少代码编码规范问题和好的代码建议,并学到不少自己之前没有注意到的Java方便的基础知识,感觉很不错,把相关明白的好的规则 ...
- openstack core components use 总结
1,附加volume(块存储,云硬盘)到vmInstances(虚拟机实列)
- Nanjing GDG Meetup 8月线下活动
致各位亲爱的 Google 技术爱好者 很高兴的通知各位朋友,Nanjing GDG 将在本周六 (08/31) 举办线下活动,讨论 Android 开发实战技巧,热烈欢迎大家报名参加. 时间: 8 ...
- JS 之 offsetWidth\offsetleft
- #include <memory>
1 auto_ptr 2 unique_ptr 1 auto_ptr C++的auto_ptr所做的事情,就是动态分配对象以及当对象不再需要时自动执行清理. 使用std::auto_ptr,要#inc ...
- C# 文件帮助类
using System; using System.Data; using System.Configuration; using System.Linq; using System.Web; us ...
- xcode - 触摸移动
第一步 创建一个UIView类 命名MoveView #import "MoveView.h" @implementation MoveView /** 移动事件 */ -(vo ...