Hi All,
Is it possible to cache a gridview in asp.net ?Please reply.
How to cache a gridview in ASP.Net
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Manikavelu VelayuthamRank #413 · 6K reputationPosted Aug 26, 2010, 1:24 AM EDT
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.