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] Queue Reconstruction by Height 根据高度重建队列
Suppose you have a random list of people standing in a queue. Each person is described by a pair of ...
- C#进阶系列——WebApi 跨域问题解决方案:CORS
前言:上篇总结了下WebApi的接口测试工具的使用,这篇接着来看看WebAPI的另一个常见问题:跨域问题.本篇主要从实例的角度分享下CORS解决跨域问题一些细节. WebApi系列文章 C#进阶系列— ...
- .NET跨平台之旅:在Linux上以本地机器码(native)运行ASP.NET Core站点
在将“.NET跨平台之旅”示例站点 about.cnblogs.com 从 ASP.NET 5 RC1 升级至 ASP.NET Core 1.0 (博文链接)之后,我们有一个难以抗拒的冲动 —— 体验 ...
- UDP通信
package com.slp; import java.io.IOException; import java.net.DatagramPacket; import java.net.Datagra ...
- 多线程之任务: Task 基础, 多任务并行执行, 并行运算(Parallel)
Task - 基于线程池的任务(在 System.Threading.Tasks 命名空间下) 多 Task 的并行执行 Parallel - 并行计算(在 System.Threading.Task ...
- DSO之光度标定
光度标定(Photometric Camera Calibration)是DSO(Direct Sparse Odometry)论文中比较特别的一部分.常规的vSLAM不太考虑光度标定的问题.比如基于 ...
- AutoMapper简单用法
首先在NuGet添加AutoMapper /// <summary> /// AutoMapper帮助类 /// </summary> public static class ...
- C#面向对象设计模式纵横谈——2.Singleton 单件(创建型模式)
一:模式分类 从目的来看: 创建型(Creational)模式:负责对象创建. 结构型(Structural)模式:处理类与对象间的组合. 行为型(Behavioral)模式:类与对象交互中的职责分配 ...
- Android 样式 (style) 和主题(theme)
转载:https://gold.xitu.io/post/58441c48c59e0d0056a30bc2 样式和主题 样式是指为 View 或窗口指定外观和格式的属性集合.样式可以指定高度.填充.字 ...
- Git怎样撤销一次分支的合并Merge
出现的问题: 某一天,所有的开发文件已经在development分支上,但是这时候,线上出了一个问题,需要及时修复,于是从master分支上,拉了一个bug分支,进行处理,master分支本应合并bu ...