if(IsPostBack)
return;
else
this.Label1.Text = this.Session[index]
最好把读出来的数据放到Session中,然后通过IsPostBack来确定是否是第二次打开
return;
else
this.Label1.Text = this.Session[index]
最好把读出来的数据放到Session中,然后通过IsPostBack来确定是否是第二次打开
解决方案 »
- 在C#中,一个变量取值的问题。
- 怎么创建一个单实例程序
- C#中,怎么设置可以使窗体上的文字大小随窗体大小变化而变化啊?
- 一个try catch finally的问题
- 外部组件错误,不懂啊!
- [ASP.NET]关于生成LinkButton的问题
- 江湖救急,后天就要交。求一个监视记事本保存操作的消息钩子(hook)实例代码
- opcclient开发,急送分
- 请教:得到并操作本程序主窗体对象(重新开帖)
- IP地址分配问题,比较复杂!高手进来讨论!(有图)
- 关闭窗口,然后自动刷新父窗和该父窗口的父窗口如何实现,刷新父窗口我知道,要刷新到爷爷的窗口不知道了,哈哈。
- 求一个介绍Visual Studio 2005的PPT(最好还有相关资料)
if(IsPostBack)
this.Label1.Text = this.Session[index]
else
读数据库
其次,缓存是给多个用户用比较合适。
如果给一个用户用,除非这一个用户跟服务器的交互特别频繁。
所以个人建议不适合用sessionif (Cache["KeyName"]==null) //从数据库Load数据;
{
Cache["KeyName"] = db.LoadDataTable(sqlString); //这最好弄个DataAccess调用
}if (Cache["KeyName"]!=null) //万一从数据库Load失败
{
DataTable dt = (DataTable)Cache["KeyName"];
//然后从DataTable中select你需要的数据返回
//return ....
}当然ds ,dt啥的都可以放cache里,就看你的需求了
string key = basicKey + "List_All";
if (HttpRuntime.Cache[key] != null)
return (DataTable)HttpRuntime.Cache[key];
else
{
if (UnitType != "" && UnitType != null)
{
strWhere += "and type like '%" + UnitType + "%'";
}
if (unit_id != "" && unit_id != null)
{
strWhere += "and unit_id='" + unit_id + "'";
}
if (branch_id != "" && branch_id != null)
{
strWhere += "and branch_id='" + branch_id + "'";
} if (peotype != "" && peotype != null)
{
strWhere += "and peotype like '%" + peotype + "%'";
}
if (name != "" && name != null)
{
strWhere += "and name like '%" + name + "%'";
}
if (idcard != "" && idcard != null)
{
strWhere += "and idcard like '%" + idcard + "%'";
}
if (flag != "" && flag != null)
{
strWhere += "and flag like '%" + flag + "%'";
}
if (sex != "" && sex != null)
{
strWhere += "and sex like '%" + sex + "%'";
}
if (xzqh == "230000")
{
strWhere += "and xzqh like '%2300%'";
}
else
{
strWhere += " and xzqh='" + xzqh + "'";
}
StringBuilder strSql = new StringBuilder();
strSql.Append("select top 5000* from View_PeopleSearche");
if (strWhere.Trim() != "")
{
strSql.Append(" where " + strWhere.Substring(4, strWhere.Length - 4));
}
dt = sqldata.GetTable(strSql.ToString());
Caches.TryAddCache(key, dt, System.Web.Caching.CacheItemPriority.Normal);
return dt;