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.牛无论触了人的儿 ...
随机推荐
- [LeetCode] Sum of Left Leaves 左子叶之和
Find the sum of all left leaves in a given binary tree. Example: 3 / \ 9 20 / \ 15 7 There are two l ...
- Redis初识、设计思想与一些学习资源推荐
一.Redis简介 1.什么是Redis Redis 是一个开源的使用ANSI C 语言编写.支持网络.可基于内存亦可持久化的日志型.Key-Value 数据库,并提供多种语言的API.从2010 年 ...
- 用vue.js学习es6(二):let和const使用
一.运行及关闭运行: 在上一节中我们用shift+右击在C:\vue\es6文件夹中打开命令行使用:npm run dev,打开了我们的vue界面. 如果要关闭则在命令行中按住ctrl+C则可以关闭. ...
- php 2038年问题
在mysql中存放日期时可以存放整数 (int), 而int可以存放的数据最大为4294967295(无符号), 而php最大为2147483647, 要显示一个大于2038年日期,该如何处理 ? ...
- BZOJ 3489: A simple rmq problem
3489: A simple rmq problem Time Limit: 40 Sec Memory Limit: 600 MBSubmit: 1594 Solved: 520[Submit] ...
- linux安装Jenkins
一.下载jenkins 最新地址在:https://jenkins.io 我下载的是:Jenkins 2.35.war,下载好直接放到tomcat的webapp目录里,启动tomcat就可以运行了 二 ...
- 推荐一款Linux下的开源编辑器
Sublime编辑器,下载地址.下载后解压,解压到家目录下,为解压后的文件夹里的可执行文件添加环境变量, vim ~/.bashrc 打开配置环境变量的文件,在最后一行添加export PATH=&q ...
- js 闭包
this.color = "blue"; (function(_this) { setInterval(function() { if (_this.color !== " ...
- thinkphp模型
1.获取系统常量信息的方法:在控制器DengLuController里面下写入下面的方法,然后调用该方法. public function test() { //echo "这是测试的&qu ...
- ORA-01438: 值大于为此列指定的允许精度
Number的数据声明如下:表示 作用 说明Number(p, s) 声明一个定点数 p(precision)为精度,s(scale)表示小数点 ...