Thanks in Advance!!!
I have a scenario of applying paging in gridview.
data to the grid will be fetched from a collection.
Now I will apply paging to it.Lets suppose
page size is 10 .I retrieve 50,000 records.
Now when I click any page number in the grid it has to retrive only 10 records from the collection and show that in the grid.
This benefits me in not hitting the database again and impoves my performance.
Suggest some best approach to do this ?
Loading
Andrew FensterPosted May 13, 2011, 11:45 AM
<asp:GridView ID="GridView1" runat="server" AllowPaging="true" PageSize="10" onpageindexchanged="GridView1_PageIndexChanging" />
Then you have to code. This example gets the data and stores it in the Cache. So you only hit the database once. When the user goes to another page, you update the GridView's page index, get the data out of the Cache and bind the grid again.
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
BindTheGrid();
}
private List
{
// If the data is stored in the Cache already, get it from there.
if (Cache["theData"] != null)
return (List
// If the data isn't already in the Cache
List
for (int x = 0; x < 50000; x++)
theData.Add("This is row #" + x.ToString());
Cache["theData"] = theData;
return theData;
}
private void BindTheGrid()
{
GridView1.DataSource = GetTheData();
GridView1.DataBind();
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
BindTheGrid();
}
Suthish NairPosted May 13, 2011, 2:44 AM
GridView Sorting, Paging without using Session, ViewState or Cache
Abhimanyu K VatsaPosted May 13, 2011, 2:21 AM
::::::::::::::::::::::::::::::::::::::