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流派,它的特点是各个弱学习器之间没有依赖关系,可以并行拟合. ...
随机推荐
- WEKA,一个开源java的数据挖掘工具
开始研究WEKA,一个开源java的数据挖掘工具. HS沉寂这么多天,谁知道偏偏在我申请离职的时候给我安排了个任务,哎,无语. 于是,今天看了一天的Weka. 主要是看了HS提供的三个文章(E文,在g ...
- BZOJ 1179 [Apio2009]Atm(强连通分量)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1179 [题目大意] 给出一张有向带环点权图,给出一些终点,在路径中同一个点的点权只能累 ...
- applet部署,无需修改客户端设置。
1 开发applet程序,编译成jar包 2 给jar包做数字签名: (1).用keytool生成密钥: keytool -genkey -keystore myapplet.keystore - ...
- 转载:做Java开发这一年 (火龙果软件)
转载:http://www.uml.org.cn/success/201410205.asp 从去年到现在,从.NET转向Java开发(只是因为项目原因,绝对与平台好坏没有关系)差不多有一年的时间了. ...
- Putty以及adb网络调试
1.什么是SSH? SSH 为 Secure Shell 的缩写,由 IETF 的网络工作小组(Network Working Group)所制定:SSH 为建立在应用层和传输层基础上的安全协议. 传 ...
- SqlDataAdapter.Update批量数据更新
SqlDataAdapter.Update批量数据更新 使用SqlDataAdapter.Update可以方便地对数据库进行快速.批量数据更新.我们最常用的多条数据更新方法是使用循环多次执行SQL语句 ...
- 在工作空间中构建和使用catkin包
在这篇博客中将会介绍,如何在工作空间中构建和使用一个包. 首先,我们来看一下如何在catkin工作空间中,使用catkin_make工具从源文件构建和安装一个包.使用catkin_make来构建一个c ...
- Log4net 自定义字段到数据库(二)
这种方法比第一种方法麻烦些 Log4Net.config <?xml version="1.0" encoding="utf-8" ?> <c ...
- 美化 input type=file控件
大家都知道input的type=file控件默认样式是不能修改的 可以通过一个小技巧处理下 html: <a href="javascript:;" class=" ...
- php-Eclipse对php中的namespace关键字报语法错误的问题
namespace是php5.3以上才支持的, 解决办法:升级IDE 切换Eclipse中的php版本 Window > Preferences > PHP > PHP Int ...