[英]How can I use OutputCache for just one Gridview?
我的页面上没有几个Gridviews。 打开页面时必须运行数据源,所以我不能在整个页面上使用OutputCache。
但是1 Gridview并不重要,查询也是如此缓慢。 这就是为什么我需要缓存它。 1小时/ 1个查询对我来说很好。
我的联系:
try
{
OleDbConnection Connection1;
using (Connection1 = new OleDbConnection("Provider=MSDAORA.1;Data Source=DATABASE:1521/orcl;Persist Security Info=True;Password=PASSWORD;User ID=USERNAME;"))
{
string sqlQuery = "select * from TABLE";
using (OleDbDataAdapter cmd = new OleDbDataAdapter(sqlQuery, Connection1))
{
Connection1.Open();
DataTable dt = new DataTable();
cmd.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
Connection1.Close();
}
}
}
catch (Exception)
{
}
如何仅缓存1个连接?
我可以仅对1个Gridview使用OutputCache吗?
我需要从连接端进行缓存吗?
使用用户控件来缓存页面的一部分
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="MyUserControl.ascx.cs" Inherits="StackOverflowQuestions.UserControl.MyUserControl" %>
<<%@ OutputCache Duration="3600" VaryByParam="none" %>
<asp:GridView ID="gvCache" runat="server"></asp:GridView>
将您的代码放在代码后的.cs文件page_load中
protected void Page_Load(object sender, EventArgs e)
{
//your code here
}
像这样使用页面中的用户控件
注册用户控件
<%@ Register TagName="UserControl" TagPrefix="uc" Src="~/UserControl/MyUserControl.ascx" %>
像这样使用
<div>
<uc:UserControl runat="server" />
</div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.