以下是Application 存放数组的例子
前台页面代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Application.aspx.cs" Inherits="ApplicationSessionServer_Application" %>
<!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">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
=============================<br />
Application 可以存放任何对象,包括数组.<br />
以下是Application 存放数组的例子<br />
<br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="存储数组" />
<asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="读取数组" /><br />
<br />
<asp:ListBox ID="ListBox1" runat="server" Height="145px" Width="158px"></asp:ListBox></div>
</form>
</body>
</html>
<!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">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
=============================<br />
Application 可以存放任何对象,包括数组.<br />
以下是Application 存放数组的例子<br />
<br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="存储数组" />
<asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="读取数组" /><br />
<br />
<asp:ListBox ID="ListBox1" runat="server" Height="145px" Width="158px"></asp:ListBox></div>
</form>
</body>
</html>
后台代码CS:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class ApplicationSessionServer_Application : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string[] a=new string[4];
a[0] = "程序员";
a[1] = "教师";
a[2] = "工人";
a[3] = "司机";
Application.Add("a",a);//利用 Application 的 Add方法,存储Application
}
protected void Button2_Click(object sender, EventArgs e)
{
string[] b = (string[])Application["a"]; //强制类型转换.对象转换为数组,然后在 ListBox 中显示出来.
for (int i = 0; i < b.Length;i++ )
{
this.ListBox1.Items.Add(b[i]); //利用ListBox 控件显示出来。
}
}
}
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class ApplicationSessionServer_Application : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string[] a=new string[4];
a[0] = "程序员";
a[1] = "教师";
a[2] = "工人";
a[3] = "司机";
Application.Add("a",a);//利用 Application 的 Add方法,存储Application
}
protected void Button2_Click(object sender, EventArgs e)
{
string[] b = (string[])Application["a"]; //强制类型转换.对象转换为数组,然后在 ListBox 中显示出来.
for (int i = 0; i < b.Length;i++ )
{
this.ListBox1.Items.Add(b[i]); //利用ListBox 控件显示出来。
}
}
}