Click here to Skip to main content
13,096,399 members (53,371 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Dear Experts,
plz suggest me...i wrote the code for page index changing but i want to display by clicking the page2 the first page records also want to display..means as first pagerecords and second page records..

Here i want to display firstpage record to secondpage records also...
plz help me....

plz help me....the code for that...

my code is..
    <form id="form1" runat="server">
    <asp:GridView ID="Gridview1" AllowPaging="true"  AutoGenerateColumns="false" PageSize="6" runat="server" DataKeyNames="id" OnPageIndexChanging="gvdetails_PageIndexChanging" Width="300px">
    <asp:BoundField DataField="id" HeaderText="id"  />
    <asp:BoundField DataField="Name" HeaderText="Name" />
    <asp:BoundField DataField="location" HeaderText="location"/>

protected void Page_Load(object sender, EventArgs e)
        if (!IsPostBack)
    private void BindGridData()
        string s = "select * from contact";
        SqlCommand cmd = new SqlCommand(s, con);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataTable dt = new DataTable();
        Gridview1.DataSource = dt;
    protected void gvdetails_PageIndexChanging(object sender, GridViewPageEventArgs e)
        Gridview1.PageIndex = e.NewPageIndex;
Posted 18-Sep-12 0:50am
Updated 18-Sep-12 1:25am
Tejas_Vaishnav 18-Sep-12 9:33am
for your solutions you need to go for lazy loading concept.
Member 9376025 21-Sep-12 5:20am
vaishnav.what is the lazy loading can explain me..
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You just need to change the page size. if you want to view previous data

protected void gvdetails_PageIndexChanging(object sender, GridViewPageEventArgs e)
        Gridview1.PageIndex = 0;

Member 9376025 21-Sep-12 5:09am
i used the above code but the secondpage data is displaying upto 10..and on clicking 3rd page all the records is displaying..
arshad alam 22-Sep-12 2:04am
it means that you have only 10x3=30 records
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

For this kind of requirement, I guess you have to store the data in ViewState and show it in the second page.

I can give you one link Preserving state of Checkboxes while paging in ASP.Net GridView Control[^], where it preserves the state of Check Boxes in View State.

You can implement the logic as per your requirements.

All the best.
Happy coding...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.170813.1 | Last Updated 19 Sep 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100