Hi All,
Is it possible to cache a gridview in asp.net ?Please reply.
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Manikavelu VelayuthamPosted Aug 26, 2010, 5:24 AM
private void CacheGrid()
{
if (Cache["DataSet"] == null)
{
SqlConnection con = new SqlConnection("ConnectionString");
SqlDataAdapter ad = new SqlDataAdapter("select * from table", con);
DataSet ds = new DataSet();
ad.Fill(ds);
Cache.Insert("DataSet", ds, null , DateTime.Now.AddMinutes(5), TimeSpan.Zero);
GridView1.DataSource = ds;
}
else
GridView1.DataSource = (DataSet)Cache["DataSet"];
GridView1.DataBind();
}
}
mark this post as accepted answer, if this post really helped you.