Application对象、ViewState对象、分页展示--2017年1月4日
Application对象
存储 Application 变量 Application["application名称"] = "application的值";
取回 Application 变量 string str = Application["application名称"];
常用的属性和方法
|
All |
返回全部的Application对象变量到一个对象数组 |
|
|
AllKeys |
返回全部的Application对象变量到一个字符串数组 |
|
|
Count |
取得Application中对象变量的数量 |
|
|
Item |
Application变量名称传回的内容值 |
|
|
Add |
新增一个Application变量值 |
|
|
Clear |
清空全部Application变量值 |
|
|
Get |
变量名传回的变量值 |
|
|
Set |
更新Application变量值 |
|
|
Lock |
锁定所有Application变量值 |
|
|
UnLock |
解除锁定Application变量 |
Application对象特性:
存储的物理位置:服务器内存。
存储的类型限制:任意类型。
状态使用的范围:整个应用程序。
存储的大小限制:任意大小。
生命周期:应用程序开始的时候创建(准确来说是用户第一次请求某URL的时候创建),应用程序结束的时候销毁。
安全与性能:数据总是存储在服务端,安全性比较高,但不易存储过多数据。
优缺点与注意事项:检索数据速度快,但缺乏自我管理机制,数据不会自动释放。
ViewState:
用于记录页面的一些Value,
GET:URL?表单元素Name=表单元素Value&表单元素Name=表单元素Value
webform中微软已经给我们做好了这个对象,自带此功能。
分页显示
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Index.aspx.cs" Inherits="Index" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<link rel="stylesheet" href="css/goupiao.css" type="text/css" />
<link rel="stylesheet" href="css/bootstrap.min.css" />
<link rel="stylesheet" href="css/font-awesome.css" />
</head>
<body>
<div class="content-bg"></div>
<div class="bg-overlay"></div>
<div class="main-posts" style="top: 38px;">
<div class="container" style="padding: 0px; box-shadow: 1px 2px 3px #000; background-color: white;">
<div style="height: 200px; background-color: white; text-align: center; line-height: 180px; font-size: 60px; background-color: white; background-image: url(images/1.png); background-size: 70%; background-repeat: no-repeat; background-position: center">
</div>
<div style="height: 20px; text-align: right;">Low爆了的字</div>
</div>
</div>
<div class="main-posts" style="top: 38px;">
<div class="container">
<form id="form1" runat="server">
<div>
<div style="height: 60px; text-align: center; position: relative">
<div style="position: relative; color: white; float: left; height: 50px; line-height: 50px;">
<asp:Button ID="luru1" runat="server" Text="添加员工" Style="display: none;" />
<asp:Button ID="luru2" runat="server" Text="上架物品" Style="display: none;" />
<div runat="server" class="luru luru1" onclick="onc1()">
添加员工
</div>
<div runat="server" class="luru luru2" onclick="onc2()">
上架物品
</div>
<div runat="server" class="zhuang" style="background-color: orange;margin-left:120px;">
</div>
<div runat="server" class="zhuangg">
过期
</div>
<div runat="server" class="zhuang" style="background-color: red;">
</div>
<div runat="server" class="zhuangg">
缺货
</div>
<div runat="server" class="zhuang">
</div>
<div runat="server" class="zhuangg">
正常
</div>
</div>
<div style="position: relative; color: white; float: right; width: 300px; height: 50px; line-height: 50px;">
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:LinkButton ID="LinkButton1" runat="server">退出登陆</asp:LinkButton>
</div>
</div>
<asp:Repeater ID="Repeater1" runat="server">
<HeaderTemplate>
<table id="tit">
<tr>
<td>编号</td>
<td>货物名称</td>
<td>销售价格</td>
<td>进货价格</td>
<td>库存数量</td>
<td>进货日期</td>
<td>保质期</td>
<td>操作</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr class="ttt" style="<%#Eval("Warnings") %><%#Eval("EDatestyle") %>">
<td><%#Eval("Ids") %></td>
<td><%#Eval("Name") %></td>
<td><%#Eval("Price") %></td>
<td><%#Eval("Bid") %></td>
<td><%#Eval("Stock") %></td>
<td><%#Eval("PDatestr") %></td>
<td><%#Eval("EDatestr") %></td>
<td>
<div class="choosetwo">
<a class="fa fa-shopping-cart aa" href="ADDnum.aspx?UserName=<%= Request["UserName"] %>&Ids=<%#Eval("Ids") %>">进货</a>
<a class="fa fa-gears aa" href="Updata.aspx?UserName=<%= Request["UserName"] %>&Ids=<%#Eval("Ids") %>">修改</a>
<a class="fa fa-level-down aa" href="Delete.aspx?UserName=<%= Request["UserName"] %>&Ids=<%#Eval("Ids") %>">下架</a>
</div>
</td>
</tr>
</ItemTemplate>
<%-- <AlternatingItemTemplate>
<tr style="<%#Eval("Warnings") %><%#Eval("EDatestyle") %> font-size:15px;font-weight:bold;">
<td><%#Eval("Ids") %></td>
<td><%#Eval("Name") %></td>
<td><%#Eval("Price") %></td>
<td><%#Eval("Bid") %></td>
<td><%#Eval("Stock") %></td>
<td><%#Eval("PDatestr") %></td>
<td><%#Eval("EDatestr") %></td>
<td>
<div class="choosetwo">
<a class="fa fa-shopping-cart aa" onclick="xcz(2)">进货</a>
<a class="fa fa-gears aa" onclick="xcz(2)">修改</a>
<a class="fa fa-level-down aa" onclick="xcz(2)">下架</a>
</div>
</td>
</tr>
</AlternatingItemTemplate>--%>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</div>
<div style="color:#FFF">当前第【<asp:Label ID="Label_NowPage" runat="server" Text="Label"></asp:Label>】页
共【<asp:Label ID="Label_MaxPage" runat="server" Text="Label"></asp:Label>】页
<asp:LinkButton ID="btn_first" runat="server">首页</asp:LinkButton>
<asp:LinkButton ID="btn_prev" runat="server">上一页</asp:LinkButton>
<asp:LinkButton ID="btn_next" runat="server">下一页</asp:LinkButton>
<asp:LinkButton ID="btn_last" runat="server">末页</asp:LinkButton>
<asp:DropDownList ID="DropDownList1" AutoPostBack="true" runat="server"></asp:DropDownList>
<asp:Button ID="Button1" runat="server" Text="跳转" />
</div>
</form>
</div>
</div>
</body>
</html>
<script type="text/javascript">
function onc1() {
document.getElementById('luru1').click();
}
function onc2() {
document.getElementById('luru2').click();
}
</script>
前台
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Index : System.Web.UI.Page
{
; //每页显示条数
public int MaxPageNumber()
{
List<Commodity> clist = new CommodityData().Select();
double end2 = Math.Ceiling(clist.Count / (Count * 1.0));
int end = Convert.ToInt32(end2);
return end;
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Label_NowPage.Text = ";
Label_MaxPage.Text = MaxPageNumber().ToString();
Repeater1.DataSource = );
Repeater1.DataBind();
pandin();
int max = MaxPageNumber();
DropDownList1.Items.Clear();
; i <= max; i++)
{
DropDownList1.Items.Add(new ListItem(i.ToString(), i.ToString()));
}
}
#region 地址栏传值:取值
if (true)
{
//string un = Request["UserName"];//地址栏传值:取值
//if (!String.IsNullOrEmpty(un))
//{
// Users u = new UsersData().select(un);
// Label1.Text = "ssssssssssssssssss";
// if (u != null)
// {
// Label1.Text = u.PName + ",欢迎回来!";
// }
// else
// {
// Response.Redirect("Login.aspx");
// }
//}
//else
//{
// Response.Redirect("Login.aspx");
//}
}
#endregion
#region Session全局传值:取值
if (true)
{
//if (Session["UserName"] != null)
//{
// string un = Session["UserName"].ToString();//Session全局传值
// Users u = new UsersData().select(un);
// if (u != null)
// {
// Label1.Text = u.PName + ",欢迎回来!";
// }
// else
// {
// Response.Redirect("Login.aspx");
// }
//}
//else
//{
// Response.Redirect("Login.aspx");
//}
}
#endregion
#region cookie全局传值:取值
if (true)
{
if (Request.Cookies["UserName"] != null)
{
string un = Request.Cookies["UserName"].Value;//Session全局传值
Users u = new UsersData().select(un);
if (u != null)
{
Label1.Text = u.PName + ",欢迎回来!";
}
else
{
Response.Redirect("Login.aspx");
}
}
else
{
Response.Redirect("Login.aspx");
}
}
#endregion
//Repeater1.DataSource = new CommodityData().Select();
//Repeater1.DataBind();
LinkButton1.Click += LinkButton1_Click;
luru2.Click += luru2_Click;
DropDownList1.SelectedIndexChanged += Button1_Click;
btn_first.Click += btn_first_Click;//首页按钮
btn_prev.Click += btn_prev_Click;
btn_next.Click += btn_next_Click;
btn_last.Click += btn_last_Click;
Button1.Click += Button1_Click;
}
void Button1_Click(object sender, EventArgs e)
{
int nextPage = Convert.ToInt32(DropDownList1.SelectedValue);
Repeater1.DataSource = new CommodityData().Select(Count, nextPage);
Repeater1.DataBind();
Label_NowPage.Text = nextPage.ToString();
pandin();
}
void btn_first_Click(object sender, EventArgs e)
{
Repeater1.DataSource = );
Repeater1.DataBind();
Label_NowPage.Text = ";
pandin();
}
void btn_prev_Click(object sender, EventArgs e)
{
;
Repeater1.DataSource = new CommodityData().Select(Count, nextPage);
Repeater1.DataBind();
Label_NowPage.Text = nextPage.ToString();
pandin();
}
void btn_next_Click(object sender, EventArgs e)
{
;
Repeater1.DataSource = new CommodityData().Select(Count, nextPage);
Repeater1.DataBind();
Label_NowPage.Text = nextPage.ToString();
pandin();
}
void btn_last_Click(object sender, EventArgs e)
{
int hehe = MaxPageNumber();
Repeater1.DataSource = new CommodityData().Select(Count, hehe);
Repeater1.DataBind();
Label_NowPage.Text = hehe.ToString();
pandin();
}
void luru2_Click(object sender, EventArgs e)
{
//string un = Request["UserName"];//地址栏传值:取值
//string un = Session["UserName"].ToString();//Session全局传值
string un = Request.Cookies["UserName"].Value;//cookie全局传值
Response.Redirect("ADDComm.aspx?UserName=" + un);
}
void pandin()
{
int NowPage = Convert.ToInt32(Label_NowPage.Text);
int MaxPage=Convert.ToInt32(Label_MaxPage.Text);
)
{
DropDownList1.Enabled = false;
btn_first.Enabled = false;
btn_prev.Enabled = false;
btn_next.Enabled = false;
btn_last.Enabled = false;
Button1.Enabled = false;
}
else if (NowPage >= MaxPage)
{
DropDownList1.Enabled = true;
btn_first.Enabled = true;
btn_prev.Enabled = true;
btn_next.Enabled = false;
btn_last.Enabled = false;
Button1.Enabled = true;
}
)
{
DropDownList1.Enabled = true;
btn_first.Enabled = false;
btn_prev.Enabled = false;
btn_next.Enabled = true;
btn_last.Enabled = true;
Button1.Enabled = true;
}else
{
DropDownList1.Enabled = true;
btn_first.Enabled = true;
btn_prev.Enabled = true;
btn_next.Enabled = true;
btn_last.Enabled = true;
Button1.Enabled = true;
}
}
void LinkButton1_Click(object sender, EventArgs e)
{
//Session.Contents.Remove("UserName");
Response.Redirect("Login.aspx");
}
}
后台
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
/// <summary>
/// CommodityData 的摘要说明
/// </summary>
public class CommodityData
{
SqlConnection conn = null;
SqlCommand cmd = null;
public CommodityData()
{
conn = new SqlConnection("server=.;database=WareHouse;user=sa;pwd=0928");
cmd = conn.CreateCommand();
}
/// <summary>
/// 查找所有数据
/// </summary>
/// <returns></returns>
public List<Commodity> Select()
{
List<Commodity> list = new List<Commodity>();
cmd.CommandText = "select *from Commodity";
conn.Open();
SqlDataReader dr = cmd.ExecuteReader();
if (dr.HasRows)
{
while (dr.Read())
{
Commodity u = new Commodity();
u.Ids = (];
u.Name = (];
u.Price = (];
u.Bid = (];
u.Stock = (];
u.Warning = (];
u.PDate = (DateTime)dr[];
u.EDate = (];
list.Add(u);
}
}
conn.Close();
return list;
}
/// <summary>
/// 查找某几条数据
/// </summary>
/// <returns></returns>
public List<Commodity> Select(int count, int NowPage)
{
List<Commodity> list = new List<Commodity>();
cmd.CommandText = ) * count) + " Ids from Commodity)";
conn.Open();
SqlDataReader dr = cmd.ExecuteReader();
if (dr.HasRows)
{
while (dr.Read())
{
Commodity u = new Commodity();
u.Ids = (];
u.Name = (];
u.Price = (];
u.Bid = (];
u.Stock = (];
u.Warning = (];
u.PDate = (DateTime)dr[];
u.EDate = (];
list.Add(u);
}
}
conn.Close();
return list;
}
/// <summary>
/// 根据ID查找
/// </summary>
/// <param name="Uname"></param>
/// <returns></returns>
public Commodity select(string Uname)
{
Commodity u = null;
cmd.CommandText = "select * from Commodity where Ids=@a";
cmd.Parameters.Clear();
cmd.Parameters.AddWithValue("@a", Uname);
conn.Open();
SqlDataReader dr = cmd.ExecuteReader();
if (dr.HasRows)
{
dr.Read();
u = new Commodity();
u.Ids = (];
u.Name = (];
u.Price = (];
u.Bid = (];
u.Stock = (];
u.Warning = (];
u.PDate = (DateTime)dr[];
u.EDate = (];
}
conn.Close();
return u;
}
/// <summary>
/// 执行TSQL语句
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public int zhixing(string str)
{
conn.Open();
try
{
cmd.CommandText = str;
int i = cmd.ExecuteNonQuery();
conn.Close();
return i;
}
catch (Exception ex)
{
conn.Close(); ;
}
}
/// <summary>
/// 插入数据
/// </summary>
/// <param name="u"></param>
/// <returns></returns>
public bool ins(Commodity u)
{
cmd.Parameters.Clear();
cmd.Parameters.AddWithValue("@UserName", u.Name);
cmd.Parameters.AddWithValue("@pwd", u.Price);
cmd.Parameters.AddWithValue("@nick", u.Bid);
cmd.Parameters.AddWithValue("@sex", u.Stock);
cmd.Parameters.AddWithValue("@bir", u.Warning);
cmd.Parameters.AddWithValue("@nation", u.PDate);
cmd.Parameters.AddWithValue("@cla", u.EDate);
)
{
return true;
}
else
{
return false;
}
}
}
访问
Application对象、ViewState对象、分页展示--2017年1月4日的更多相关文章
- WebForm Repeater的事件、后天数据展示--2017年1月8日
Repeater的Command操作 1.ItemCommand事件 :在Repeater中所有能触发事件的控件,都会来触发这一个事件 CommandName : 判断点击的是什么按钮,e.Comma ...
- 适用于 Windows 7 SP1 和 Windows Server 2008 R2 SP1 的 .NET Framework 4.6、4.6.1、4.6.2 和 4.7 以及适用于 Windows Server 2008 SP2 的 .NET Framework 4.6 仅安全更新说明:2017 年 9 月 12 日
https://support.microsoft.com/zh-cn/help/4040957/description-of-the-security-only-update-for-the-net ...
- 适用于 Windows 7 SP1、Windows Server 2008 R2 SP1 和 Windows Server 2008 SP2 的 .NET Framework 4.5.2 仅安全更新说明:2017 年 9 月 12 日
https://support.microsoft.com/zh-cn/help/4040960/description-of-the-security-only-update-for-the-net ...
- 2017年8月9日学习内容存放 #socket通信介绍
2017年8月9日学习内容存放 #socket通信介绍 ''' OSI七层 应用 表示 会话 传输 网络 ip 数据链路 mac 物理层 网线 http smtp dns ftp ssh snmp i ...
- 【2017年9月10日更新】ABP配套代码生成器(ABP Code Generator)帮助文档,实现快速开发
ABP代码生成器介绍 ABP Code Generator 针对abp这个框架做了一个代码生成器,功能强大.分为两大功能点,一个是数据层,一个是视图层. 数据服务层:通过它,可以实现表设计.领域层初始 ...
- 2017年4月16日 一周AnswerOpenCV佳作赏析
2017年4月16日 一周AnswerOpenCV佳作赏析 1.HelloHow to smooth edge of text in binary image, based on threshold. ...
- 猖獗的假新闻:2017年1月1日起iOS的APP必须使用HTTPS
一.假新闻如此猖獗 刚才一位老同事 打电话问:我们公司还是用的HTTP,马上就到2017年了,提交AppStore会被拒绝,怎么办? 公司里已经有很多人问过这个问题,回答一下: HTTP还是可以正常提 ...
- [转载]Ubuntu17.04(Zesty Zapus)路线图发布:2017年4月13日发布
Canonical今天公布了Ubuntu 17.04(Zesty Zapus)操作系统的发布路线图,该版本于今年10月24日上线启动,toolchain已经上传且首个daily ISO镜像已经生成.面 ...
- 2017年1月5日 星期四 --出埃及记 Exodus 21:31
2017年1月5日 星期四 --出埃及记 Exodus 21:31 This law also applies if the bull gores a son or daughter.牛无论触了人的儿 ...
随机推荐
- 【原】Learning Spark (Python版) 学习笔记(四)----Spark Sreaming与MLlib机器学习
本来这篇是准备5.15更的,但是上周一直在忙签证和工作的事,没时间就推迟了,现在终于有时间来写写Learning Spark最后一部分内容了. 第10-11 章主要讲的是Spark Streaming ...
- 使用SVG图像作为loading加载 以保证图像高清不模糊
使用教程 接下来设计达人网小编为大家讲解这个使用方法,其实是相当简单的. STEP 1: 复制你想要的SVG加载动画代码到<body>里面,小编随意复制一个代码如下:<svg ver ...
- celery 框架
转自:http://www.cnblogs.com/forward-wang/p/5970806.html 生产者消费者模式 在实际的软件开发过程中,经常会碰到如下场景:某个模块负责产生数据,这些数据 ...
- Spring缓存机制的理解
在spring缓存机制中,包括了两个方面的缓存操作:1.缓存某个方法返回的结果:2.在某个方法执行前或后清空缓存. 下面写两个类来模拟Spring的缓存机制: package com.sin90lzc ...
- windows server 2008 各版本号下载地址(微软官网)
前言: 微软官网上下载系统的镜像文件要远比百度网盘下载起来得更快. Windows Server 2008 32-bit Standard(标准版)
- Sass学习笔记
语法 @each $var in <list>//循环就是去遍历一个列表,然后从列表中取出对应的值 @while $types > 0 //循环直到函数不成立 SASS函数 To-u ...
- POJ 2186 Popular Cows(Targin缩点)
传送门 Popular Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 31808 Accepted: 1292 ...
- 定位框一闪而过 iOS Swift
需求:获取经纬度. 方案:我自定义了一个类模块CLLocationModule.swift 备注以下代码里 let IS_IOS8 = (UIDevice.currentDevice().system ...
- easyUI 如何不跳转页面,只是加载替换center部分内容
以前做的一个故障报修系统,前端框架使用easyUI框架,layout布局,center使用datagrid .点击左边树形菜单时时页面跳转,想要知道如何点击菜单时不进行页面跳转,而是只对center模 ...
- jvascript 顺序查找和二分查找法
第一种:顺序查找法 中心思想:和数组中的值逐个比对! /* * 参数说明: * array:传入数组 * findVal:传入需要查找的数 */ function Orderseach(array,f ...