自定义控件在前台加入:
<%@ 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();
}
{
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();
}