<!--StartFragment--><%@ Page Language="C#" EnableViewState = "true"%>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Configuration" %>
<%@ import Namespace="System.Collections" %>
<%@ import Namespace="System.Collections.Specialized" %>
<%@ import Namespace="System.Data" %>
<script runat="server">
//http://aspalliance.com/aldotnet/examples/cacheviewer.aspx
//http://scottwater.com
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
hlRefresh.NavigateUrl = Request.RawUrl;
BindGrid();
}
}

//绑定到DataGrid
private void BindGrid()
{
//创建arraylist来保存cacheditem信息
ArrayList al = new ArrayList();
IDictionaryEnumerator CacheEnum = Cache.GetEnumerator();
while (CacheEnum.MoveNext())
{
al.Add(new CachedItem(CacheEnum.Key.ToString(),CacheEnum.Value.GetType().ToString()));
}
litCount.Text = al.Count.ToString();
dgCachedItems.DataSource = al;
dgCachedItems.DataBind();
}

//删除Cache项
protected void Grid_ItemCommand(object sender, DataGridCommandEventArgs e)
{
HyperLink l = (HyperLink)e.Item.FindControl("CacheItemName");
//确保我们找到了该项
if(l != null)
{
Cache.Remove(l.Text);
}
this.BindGrid();
}

protected void Grid_Created(object sender, DataGridItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
((Literal)e.Item.FindControl("Counter")).Text = (e.Item.ItemIndex + 1).ToString();
}
}
private class CachedItem
{
public CachedItem(){}
public CachedItem(string key, string type)
{
this.CacheKey = key;
this.CacheType = type;
}

private string _cacheKey;
public string CacheKey
{
get {return this._cacheKey;}
set {this._cacheKey = value;}
}

private string _cacheType;
public string CacheType
{
get {return this._cacheType;}
set {this._cacheType = value;}
}
}

//Remove All
void lbRemoveAll_Click(object sender, EventArgs e)
{
IDictionaryEnumerator CacheEnum = Cache.GetEnumerator();
while (CacheEnum.MoveNext())
{
Cache.Remove(CacheEnum.Key.ToString());
}
BindGrid();
}

</script>
<html>
<head>
<title>Cache管理器</title>
<style>
TD,A,P,SPAN {font-size:9pt;}
.Header {background-color:#EDEDED;text-align:center;font-weight:bold;}
</style>
</head>
<body >
<form runat="server">
浏览、删除缓存
<br/>
数量:
<asp:Literal />
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
</form>
</body>
</html>

相关文章:

  • 2021-05-30
  • 2022-01-20
  • 2021-10-19
  • 2021-08-23
  • 2021-04-09
  • 2021-11-13
  • 2021-12-04
  • 2022-12-23
猜你喜欢
  • 2021-05-23
  • 2022-12-23
  • 2021-07-18
  • 2021-08-01
  • 2021-07-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案