扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
经试验,觉得自定义控件中加入缓存,从而实现整个页的局部缓存,效果不错。
自定义控件在前台加入:
<%@ OutputCache Duration="60" VaryByParam="none" %>
后台代码:
protected void Page_Load(object sender, EventArgs e)
...{
Label1.Text = DateTime.Now.ToString();
source = (DataView)Cache["SQUARE"];
if (source == null)
...{
conn = new SqlConnection(ConfigurationManager.ConnectionStrings["GoConnectionString"].ConnectionString);
mycmd = new SqlDataAdapter("select * from GUser", conn);
DataSet ds = new DataSet();
mycmd.Fill(ds, "GUser");
source = new DataView(ds.Tables["GUser"]);
Cache["SQUARE"] = source;
}
else 
...{
}
GridView1.DataSource = source;
GridView1.DataBind();
}
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。